jbradley04 Posted October 24, 2009 Share Posted October 24, 2009 Hello, For some reason I am just not getting the right answer when I do this query and not quite sure why? $runinposition = mysql_query("SELECT * FROM bb_off WHERE user='$user' AND test1='test1' OR test2='test' OR test3='test3' OR test4='test4' OR test5='test5' OR test6='test6' AND Result1='result1'OR Result2='result2' OR Result3='result3'OR Result4='result4'"); $runinpositionresult= mysql_num_rows($runinposition); So, basically what I am trying to do is count how many test there are when the user = the user and one of the results??? :'( I am sure I am way off on this code! Any help would be great! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/178802-solved-need-help-with-a-query/ Share on other sites More sharing options...
DavidAM Posted October 24, 2009 Share Posted October 24, 2009 AND's take precedence over OR's so you have to add the parenthesis (below). This query will return all rows where user = $user AND any of the six tests AND any of the four results. SELECT * FROM bb_off WHERE user='$user' AND (test1='test1' OR test2='test' OR test3='test3' OR test4='test4' OR test5='test5' OR test6='test6') AND (Result1='result1' OR Result2='result2' OR Result3='result3' OR Result4='result4') Without the parenthesis it acts like this: SELECT * FROM bb_off WHERE (user='$user' AND test1='test1') OR test2='test' OR test3='test3' OR test4='test4' OR test5='test5' OR (test6='test6' AND Result1='result1') OR Result2='result2' OR Result3='result3'OR Result4='result4' Which is clearly NOT what you want. Quote Link to comment https://forums.phpfreaks.com/topic/178802-solved-need-help-with-a-query/#findComment-943278 Share on other sites More sharing options...
jbradley04 Posted October 24, 2009 Author Share Posted October 24, 2009 Worked like a charm! Thank you!!! Quote Link to comment https://forums.phpfreaks.com/topic/178802-solved-need-help-with-a-query/#findComment-943593 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.