Far Cry Posted June 25, 2011 Share Posted June 25, 2011 So I have a user_items table that has: userid (So it keeps track of who has the item) item_id However, I also have an items table that has: item_id item_name item_description item_type item_desc item_cost item_sell_value <?php require("styles/top.php"); ?> <?php if(isLoggedin($valid)){ ?> <center><h1>Your Items</h1></center> <?php $query = mysql_query("SELECT items.item_id FROM items LEFT JOIN user_items ON items.item_id=user_items.item_id WHERE user_items.userid='$userid'"); $numrows = mysql_num_rows($query); if($numrows > 0){ while($row = mysql_fetch_assoc($query)){ $row['item_name'] = $name; echo "you have a $name"; } } else { echo"You have no items."; } ?> <?php } else { ?> <?php } ?> When I try to echo out the name, it echos out the database name instead. Any ideas? Link to comment https://forums.phpfreaks.com/topic/240398-left-join-issue/ Share on other sites More sharing options...
Cagecrawler Posted June 25, 2011 Share Posted June 25, 2011 You're not assigning $name in that bit of code. Instead of this: $row['item_name'] = $name; You want: $name = $row['item_name']; Link to comment https://forums.phpfreaks.com/topic/240398-left-join-issue/#findComment-1234808 Share on other sites More sharing options...
Far Cry Posted June 25, 2011 Author Share Posted June 25, 2011 Part of the issue is fixed, now it's not echoing anything where the variable should be. Link to comment https://forums.phpfreaks.com/topic/240398-left-join-issue/#findComment-1234817 Share on other sites More sharing options...
jcbones Posted June 26, 2011 Share Posted June 26, 2011 LEFT JOIN will return empty results from table 2, if none exist for the corresponding row in table 1. You should use just JOIN, this will omit results that do not exist in both tables. Link to comment https://forums.phpfreaks.com/topic/240398-left-join-issue/#findComment-1234848 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.