1

Is their a code were you can use Or in a mysql query?

I used this code to find some Emails from a reciver.

mysql_query("select * from Friends where Reciver like '%$term%'");

but i want to do a code like

mysql_query("select * from Friends where Reciver or Sender like '%$term%'");

my question is? is this right because when I try it it doesn't come up with anything?

If it isn't right could you say so and say why it isn't? i learn well from my mistakes?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Ryan
  • 11
  • 3

4 Answers4

8

1st of all. Check out the dangers of SQL Injection.

2nd try this query.

select * from Friends where Reciver LIKE '%$term%' OR Sender LIKE '%$term%'
Community
  • 1
  • 1
Ólafur Waage
  • 68,817
  • 22
  • 142
  • 198
4

Here is how you do it

mysql_query("SELECT * FROM Friends WHERE Reciver LIKE '%$term%' OR Sender LIKE '%$term%'");
Ibu
  • 42,752
  • 13
  • 76
  • 103
2
select * from Friends where Reciver like '%$term%' or Sender like '%$term%';
Emil Vikström
  • 90,431
  • 16
  • 141
  • 175
2

You can do this query and for that your query should be like this:

select * from Friends where Reciver like '%$term%' or Sender like '%$term%'
Harry Joy
  • 58,650
  • 30
  • 162
  • 207