ukscotth Posted August 16, 2011 Share Posted August 16, 2011 Hi all, Anyone know why this query is giving me the wrong results ? $books2 = mysql_query("SELECT * FROM books WHERE (extra1 LIKE '%$cat%') OR (extra2 LIKE '%$cat%') OR (extra3 LIKE '%$cat%') AND type = 'public'"); Its giving me results that dont have the 'type' 'public' Any ideas ? Many thanks in advance. Scott Quote Link to comment https://forums.phpfreaks.com/topic/244912-mysql-query-problem/ Share on other sites More sharing options...
kney Posted August 16, 2011 Share Posted August 16, 2011 change to: $books2 = mysql_query("SELECT * FROM books WHERE (extra1 LIKE '%" . $cat. "%'") OR (extra2 LIKE '%" . $cat. "%'") OR (extra3 LIKE '%" . $cat. "%'") AND type = public"); Quote Link to comment https://forums.phpfreaks.com/topic/244912-mysql-query-problem/#findComment-1258070 Share on other sites More sharing options...
ukscotth Posted August 16, 2011 Author Share Posted August 16, 2011 Thanks but getting this error with that code : Parse error: syntax error, unexpected T_STRING Quote Link to comment https://forums.phpfreaks.com/topic/244912-mysql-query-problem/#findComment-1258071 Share on other sites More sharing options...
ukscotth Posted August 16, 2011 Author Share Posted August 16, 2011 it seems like its just the end part that isnt working. The AND part doesnt seem to affect the results Quote Link to comment https://forums.phpfreaks.com/topic/244912-mysql-query-problem/#findComment-1258073 Share on other sites More sharing options...
AyKay47 Posted August 16, 2011 Share Posted August 16, 2011 change to: $books2 = mysql_query("SELECT * FROM books WHERE (extra1 LIKE '%" . $cat. "%'") OR (extra2 LIKE '%" . $cat. "%'") OR (extra3 LIKE '%" . $cat. "%'") AND type = public"); concatenation is not needed.. not an expert in SQL, however perhaps you should try encasing you or statements inside of parenthesis.. $books2 = mysql_query("SELECT * FROM books WHERE ((extra1 LIKE '%$cat%') OR (extra2 LIKE '%$cat%') OR (extra3 LIKE '%$cat%')) AND type = 'public'"); Quote Link to comment https://forums.phpfreaks.com/topic/244912-mysql-query-problem/#findComment-1258077 Share on other sites More sharing options...
ukscotth Posted August 16, 2011 Author Share Posted August 16, 2011 Thanks, unfortunatly that gives the same results Quote Link to comment https://forums.phpfreaks.com/topic/244912-mysql-query-problem/#findComment-1258079 Share on other sites More sharing options...
ukscotth Posted August 16, 2011 Author Share Posted August 16, 2011 Anyone know how I can fix this ?, its driving me crazy Quote Link to comment https://forums.phpfreaks.com/topic/244912-mysql-query-problem/#findComment-1258294 Share on other sites More sharing options...
PFMaBiSmAd Posted August 16, 2011 Share Posted August 16, 2011 What was your actual query statement per what AyKay47 suggested, because forcing the operator precedence by putting () around the list of OR'ed terms would be correct. Quote Link to comment https://forums.phpfreaks.com/topic/244912-mysql-query-problem/#findComment-1258297 Share on other sites More sharing options...
ukscotth Posted August 16, 2011 Author Share Posted August 16, 2011 Ive just realised i've made a stupid mistake. It was the rest of my code that was messing me up and Aykay's code did work. Thanks very much for your help Quote Link to comment https://forums.phpfreaks.com/topic/244912-mysql-query-problem/#findComment-1258301 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.