Jump to content

Help with num_rows


EchoFool

Recommended Posts

I have two tables which have simple terms this:

 

Item ID  | User ID  | Quantity

  1              1          200

 

And the other has:

 

Item ID  | TradeAllowed |

  1                1

 

With a query like this:

$GetItems = mysql_query("SELECT useritem.ItemID,useritem.Quantity FROM useritem,item WHERE useritem.UserID='{$_SESSION['Current_User']}' AND useritem.Quantity > 0 AND item.Trade='1'")
			Or die(mysql_error());

 

But for some reason say the user has the item. and the item does exist in both tables which it should. When i echo mysql_num_rows($GetItems); it echo's 3. No idea where it gets 3 from. If anything 2 would make sense but it should only load one.

 

Why does it display 3?

Link to comment
Share on other sites

Because you don't specify that the table should be joined on itemID, so it joins each record in one tablewith each record in the other.

 

<?php
$GetItems = mysql_query("SELECT useritem.ItemID,useritem.Quantity 
            FROM useritem
                INNER JOIN item ON useritem.itemID = item.itemID
            WHERE useritem.UserID='{$_SESSION['Current_User']}' 
            AND useritem.Quantity > 0 
            AND item.Trade='1'")  or die(mysql_error());
?>

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.