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
https://forums.phpfreaks.com/topic/91160-help-with-num_rows/
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
https://forums.phpfreaks.com/topic/91160-help-with-num_rows/#findComment-467227
Share on other sites

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.