So, for school I am trying to create an online store (this is a project), and for the basket I use a database where I get information based on the user and print it. HOWEVER, my while loop only finds the last element, not the other two. Now I am sure that the old data will be overwritten so that it will not be printed, but I do not know how to fix it.
this is what i got so far:
<?php
if(isset($_SESSION['userid'])){
$db = new PDO('mysql:host=localhost;dbname=ismsite', 'root', 'e-scooter');
$result = $db->prepare("SELECT * FROM cart where user_id=:userid ORDER BY cart_id DESC LIMIT 3 ");
$result->bindParam(':userid', $_SESSION['userid']);
$result->execute();
$info = array();
while($row = $result->fetch(PDO::FETCH_ASSOC)){
$pid = $row['product_id'];
$quantity = $row['quantity'];
$result = $db->prepare("SELECT * FROM Products WHERE productID=:pid");
$result->bindParam(':pid', $pid);
$result->execute();
while($row = $result->fetch(PDO::FETCH_ASSOC)){
echo $row['naam'];
}
}
}
else{
echo "Je moet inloggen om te kunnen winkelen.";
}
?>
Can anyone help me on this?
source
share