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
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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.