I'm trying to store an ID and Product Name into a session to be used as a shopping basket but my code is writing over the information it already has in the while loop. I think I need to use a nested array but not sure.
Can anyone point me in the right direction on what I should be searching for to learn how to fix my problem
Can anyone point me in the right direction on what I should be searching for to learn how to fix my problem
Code:
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$cart_array = array('id' => "{$row['id']}", 'name' => "{$row['product_name']}");
$_SESSION['cart'] = $cart_array;
}
foreach($_SESSION['cart'] as $key=>$value)
{
echo $value . ' <br />';
}