Jump to content

Help with query


EchoFool

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 i will put in red and the other is the one that this query is meant to get. But sadly it grabs the one in red. The reason the red one is incorrect is because Trade is = 0 which is the only difference in my database. So i don't know why it's collecting that itemID of the red row instead of the black...

 

Useritem table:

ItemId | Quantity | UserID |

---1--- |-----5-----|----1-----|

---2---|-----1-----|----1-----| 

 

Item table

ItemID | Trade |

---2---|-----0-----|

---1---|-----1-----|

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.