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 "); Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.