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