petenaylor Posted May 4, 2012 Share Posted May 4, 2012 Hi all The following piece of code doesn't just bring back results where live = 1 it shows all results? Am I doing something wrong? $getproducts = mysql_query(" SELECT * FROM products WHERE live = 1 AND title LIKE \"%$term%\" OR description LIKE \"%$term%\" ORDER BY id DESC "); Link to comment https://forums.phpfreaks.com/topic/262090-mysql-query-not-filtering/ Share on other sites More sharing options...
dmikester1 Posted May 4, 2012 Share Posted May 4, 2012 WHERE live = 1 AND title LIKE \"%$term%\" OR description LIKE \"%$term%\" What do you want here? WHERE (live = 1 AND title LIKE \"%$term%\") OR description LIKE \"%$term%\" - or - WHERE live = 1 AND (title LIKE \"%$term%\" OR description LIKE \"%$term%\") Notice the change in parens. Mike Link to comment https://forums.phpfreaks.com/topic/262090-mysql-query-not-filtering/#findComment-1343163 Share on other sites More sharing options...
awjudd Posted May 5, 2012 Share Posted May 5, 2012 You are missing brackets, so the order of operations isn't working as you wanted. $query="SELECT * FROM products WHERE live = 1 AND (title LIKE '%$term%' OR description LIKE '%$term%') ORDER BY id DESC"; ~awjudd Link to comment https://forums.phpfreaks.com/topic/262090-mysql-query-not-filtering/#findComment-1343202 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.