Jump to content

[SOLVED] Need Help with a query


jbradley04

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/178802-solved-need-help-with-a-query/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.