PHP & MySQL - LEFT JOIN issue

nerdpowah23

New Member
Messages
14
Reaction score
0
Points
0
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)){
$name = $row['item_name'];
echo
"you have a $name";
}
} else {
echo
"You have no items.";
}

?>



<?php
} else {
?>



<?php
}
?>
When I try to echo out the name, it doesnt echo anything. Any ideas?
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
At a quick glance:

SELECT items.item_id

only asks for the item_id. It doesn't return the item_name.
 

nerdpowah23

New Member
Messages
14
Reaction score
0
Points
0
That seems to work now, sorry I'm just trying to get this join stuff, I'm over-thinking everything.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Did you color the sample code by hand? You don't need to do this; just use
PHP:
, [html], [code] or [c] (for inline code) tags as appropriate, which will also preserve formatting and better delineate the code.
 
Last edited:
Top