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
https://forums.phpfreaks.com/topic/94275-help-with-query/
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.