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
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

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.