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

Member Avatar for diafol

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 = ?"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.