I am attempting to run a SQL query like this:
$sql = mysql_query("select * from users where new_mail = 0 OR new_events = 0 and emailed = 1") or die(mysql_error());
while($r=mysql_fetch_array($sql))
{
mysql_query("update users set emailed = 0 where username='{$r['username']}'") or die(mysql_error());
}
However it seem to ignore the OR statements and only follows the and statement. So it goes ahead and sets emailed to 0 even if they still have new_mail or new_event. Any clue why?
Thanks for your help!
In MySQL, the
ANDoperator has a higher precedence over theORoperator.To get the logic you desire, try grouping the parameters in the way you want them to be evaluated: