Page 1 of 1

Multiple WHERE (=, LIKE)

Posted: Mon Dec 27, 2004 11:30 am
by AliasBDI
I need to have a query that checks for one field to be equal while other fields be LIKE. Here is my query, it is disregarding the = check.

Code: Select all

"SELECT * FROM con_articles WHERE active = 'Y' AND common LIKE " . $search1 . " OR common LIKE " . $search2 . " OR common LIKE " . $search3 . ""
Any ideas?

Posted: Mon Dec 27, 2004 11:46 am
by Weirdan
OR operator has higher precedence. Use parenthesis to override the precedence, like this:

Code: Select all

SELECT 
   * 
FROM 
   con_articles 
WHERE 
   active = 'Y' 
   AND (
       common LIKE '$search1'
       OR common LIKE '$search2'  
       OR common LIKE '$search3'
   )