Jump to content

Display Inner Join


Tenaciousmug

Recommended Posts

How do I display these two inner joins in a while loop?

 

$sql = "SELECT w.userid, w.itemid, i.itemid, i.image, h.itemid, h.gender, h.image, h.type
FROM {wardrobe} w
INNER JOIN {items} i
ON w.itemid = i.itemid
INNER JOIN {hawearables} h
ON i.itemid = h.itemid
WHERE w.userid='".$_SESSION['userid']."' AND h.type='Top'";
$result = mysqli_query($cxn, $sql);

 

This is what I keep putting:

$sql = "SELECT w.userid, w.itemid, i.itemid, i.image, h.itemid, h.gender, h.image, h.type
FROM {wardrobe} w
INNER JOIN {items} i
ON w.itemid = i.itemid
INNER JOIN {hawearables} h
ON i.itemid = h.itemid
WHERE w.userid='".$_SESSION['userid']."' AND h.type='Top'";
$result = mysqli_query($cxn, $sql);
while ($row = mysqli_fetch_assoc($result))
{
$image = $row['items.image'];

$tableOutput = "<img src=\"http://www.elvonica.com/".$image."\">";
}

 

But then I get this error:

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in /home1/elvonica/public_html/wardrobe/change.php on line 21
Link to comment
Share on other sites

Your problem is with all the curly braces around the table names - that is invalid code. The only reason to use curly braces in that context would be if you were enclosing variables to be replaced by PHP when parsing the string. But, if that was the case, then the variables would be preceded with a dollar sign. If those are variables, then include the dollar sign. If those are the actual table names then remove the curly braces.

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.