0

So I'm making a wishlist but am stuck at joining 2 MySQL tables together. At the moment I'm doing this by using following code:

   if ($stmt = $mysqli->prepare("SELECT ItemID FROM wishlist WHERE WishlistID = ?")) { 
        $stmt->bind_param("s", $this->ID);
        $stmt->execute();
        $stmt->bind_result($id);
        while ($product = $stmt->fetch()) { 

            if ($stmt2 = $mysqli2->prepare("SELECT products.name FROM products WHERE products.id = ?")) { 
                $stmt2->bind_param("s", $id);
                $stmt2->execute();
                $stmt2->bind_result($name);
                $stmt2->fetch();                            
                $page .= $name . "<br/>m<br/>";                                        
                $stmt2->close();
            }

        }
    }

Now this ofcourse is a workaround. This was my code for the join that didn't work:

 if ($stmt = $mysqli->prepare("SELECT products.name FROM wishlist,products WHERE wishlist.WishlistID = ? AND wishlist.ItemID = products.id")) { 

where wishlist.WishlistID is the ID of the user's wishlist, stored in a php Session.

Help would be greatly appreciated..

2
Contributors
1
Reply
12
Views
3 Years
Discussion Span
Last Post by diafol
0

Have you read up on MySQL JOIN syntax? It's a good read - recommended

Anyway, try...

"SELECT p.name FROM products AS p INNER JOIN wishlist AS w ON p.id = w.ItemID WHERE w.WishlistID = ?"
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.