takn25 Posted April 8, 2011 Share Posted April 8, 2011 Hi, I am fairly new to using OR in my queries and for some reason the result isnt what it should be please could you check the result should be NULL (0) I did an echo and it shows 1 with num rows. Ok in the mysql table the played row = 0 and c1 = 1 and c2 = 5 $cid=1; $post = "SELECT * FROM match WHERE c1 ='$cid' OR c2 = '$cid' && played ='7'"; $post_result= mysql_query($post) or die (mysql_error()); while ($row_post=mysql_fetch_assoc($post_result)) { $id=$row_post['match_id']; } $post_num=mysql_num_rows($post_result); echo $post_num; Quote Link to comment https://forums.phpfreaks.com/topic/233083-whats-wrong-in-query/ Share on other sites More sharing options...
Lyleyboy Posted April 8, 2011 Share Posted April 8, 2011 Could be && in your query instead of AND Quote Link to comment https://forums.phpfreaks.com/topic/233083-whats-wrong-in-query/#findComment-1198737 Share on other sites More sharing options...
betterphp Posted April 8, 2011 Share Posted April 8, 2011 I think AND takes priority over OR so you are efficiently doing $post = "SELECT * FROM match WHERE c1 ='$cid' OR (c2 = '$cid' && played ='7')"; now I have written that I'm not sure though. the && should defiantly be AND. Although it should give an error if that was wrong. Quote Link to comment https://forums.phpfreaks.com/topic/233083-whats-wrong-in-query/#findComment-1198740 Share on other sites More sharing options...
Maq Posted April 8, 2011 Share Posted April 8, 2011 Also, 'match' is a MySQL reserved word. You either need to change your column name, along with your queries OR put backtics `match` around it in all your queries. This seems to be a MySQL question, moving. Quote Link to comment https://forums.phpfreaks.com/topic/233083-whats-wrong-in-query/#findComment-1198796 Share on other sites More sharing options...
mikosiko Posted April 8, 2011 Share Posted April 8, 2011 +1 with Maq answer... and for the &&, AND and OR operators and precedence you can read: http://dev.mysql.com/doc/refman/5.0/en/expressions.html and http://dev.mysql.com/doc/refman/5.0/en/operator-precedence.html Quote Link to comment https://forums.phpfreaks.com/topic/233083-whats-wrong-in-query/#findComment-1198802 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.