# [web] Query grabs the wrong row.. not sure why?

This topic is 3758 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have used an inner join on 2 tables on ItemID but for some unknown reason its getting the wrong row but I don't see how. From the logic i have placed in, it cannot be possible to get the result it is getting, but im sure I've done some silly mistake in the query that i have not spotted so maybe some one here can:
<?php
$Get = mysql_query("SELECT useritem.ItemID,useritem.Quantity FROM useritem INNER JOIN item ON item.ItemID WHERE item.Trade=1 AND useritem.UserID='{$_SESSION['Current_User']}'
AND useritem.Quantity>0")
Or die(mysql_error());
?>

I'll show ya the table layout i have with 2 items in ... one is the incorrect one which is ItemID 2. Item 1 is the row that this query is meant to get. But sadly it grabs the ItemID 2. The reason ItemID2 is incorrect is because Trade is = 0 and the query asks for items with trade=1 which is the only difference in my database. So i don't know why it's collecting that itemID2 row instead of the ItemID1... User item table:
Quote:
 ItemId | Quantity | UserID | ---1--- |-----5-----|----1-----| ---2---|-----1-----|----1-----|
Item table
Quote:
 ItemID | Trade | ---2---|-----0-----| ---1---|-----1-----|
Can any one see what I did wrong?

##### Share on other sites
Here's my guess. Change highlighted in bold

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

##### Share on other sites
Quote:
 Original post by SanderHere's my guess. Change highlighted in bold0") Or die(mysql_error());?>

Argh i see! It's working now ! Thank you very much Sander!

• 37
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631360
• Total Posts
2999554
×