KPO
KPO

Reputation: 880

How to use OR multiple times in a Where statement?

I want to do something like "Where conditions = '$condition' OR conditions = '$condition2' OR conditions = '$condition3' but that returns all entries in the database versus the ones i am looking for.. what i can i do to make this work?

$sql = "SELECT STRAIGHT_JOIN DISTINCT table1.person_id, table1.full_name, 
table2.stuff_id, table2.stuff_name, table3.whatever_why, 
table3.whatever_comments, table3.whatever_test_id
from table1 
join table4 on table1.person_id = table4.person_id 
join table2 on table4.stuff_id  = table2.stuff_id
join table3 on table1.person_id = table3.person_id 
WHERE conditions = '$condition' and ( (
     table3.whatever_why like '%$q%'
  OR table3.whatever_comments like '%$q%'
  OR table3.whatever_name like '%$q%'
))
order by table3.id DESC limit $startrow, 10";

$result = mysql_query($sql);

Upvotes: 0

Views: 135

Answers (2)

roselan
roselan

Reputation: 3775

Where conditions in ('$condition1', '$condition2', '$condition3')

Upvotes: 1

Randy
Randy

Reputation: 16673

you may use parenthesis to group up your logic.

just continuing to list OR statements will match the rows if any of those are true.

Upvotes: 3

Related Questions