我试图允许用户将目的地添加到他们的收藏页面,类似于将产品添加到购物车。我这样做是通过将目标保存到会话数组,然后将此会话数组添加到SQL SELECT语句的末尾来打印目标。虽然我编写的代码只允许我将一个目的地添加到收藏夹。任何人都可以指出我的正确方向。
if(empty($_SESSION['cart'])){
$_SESSION['cart'] = array();
} else {
array_push($_SESSION['cart'], $_GET['theid']);
// HOW TO LOOP THROUGH SESSION CART
$str = implode(',', $_SESSION['cart']) ;
$query = "SELECT * FROM Destinations WHERE DestID IN ($str)" ;
$result = mysqli_query($connection, $query);
while($row=mysqli_fetch_assoc($result)){
echo $row['DestName'].' '.$row['DestRating'].
' <img src="Images/'.$row['DestImage'].'" /> <br/>';
}
}