Jump to content

Whats Wrong in query?


takn25

Recommended Posts

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;

Link to comment
https://forums.phpfreaks.com/topic/233083-whats-wrong-in-query/
Share on other sites

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.

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.