Jump to content
  • Advertisement
Sign in to follow this  
CelticSir

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

This topic is 3850 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!