Jump to content

[SOLVED] Stupid LEFT JOIN not working


SocomNegotiator

Recommended Posts

Ok I have a left join that takes an id from one table and then equals it to another fields table...but the result is not working for some odd reason:

 

<?php
$db->query('SELECT item.id, item.name, order.amount, order.item_id FROM `order` LEFT JOIN `item` ON order.item_id = item.id WHERE order.user_id='.$user_id) or die(mysql_error());
$iteminf = $db->fetch_array();

//I just made this so you can see how I am calling the variable
echo $iteminf['name'];
?>

 

What I have here displays a blank result...I have checked the DB and there are orders that have the item_id the same as the item tables id. So it should grab those items name based on the id being the same as in the order table, but it's not....any ideas?

Link to comment
https://forums.phpfreaks.com/topic/116458-solved-stupid-left-join-not-working/
Share on other sites

you could try this

$db->query("SELECT item.id, item.name, order.amount, order.item_id FROM `order` LEFT JOIN `item` ON order.item_id = item.id WHERE order.user_id='$user_id'") or die(mysql_error());

 

note the double quotes arround the query string and single quotes around the php variable

 

print_r($iteminf); should tell you whats exactly in the returned array

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.