Sign in to follow this  

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

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Sander
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());
?>


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

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this