Page 1 of 1

Help with session vairables (part II)

Posted: Fri Nov 19, 2004 7:33 am
by DudeBori82
How do I access the information stored into this session array, each item in it's own row in a table? (there are to be multiple items in the cart, each with it's own "Product_ID", "short_desc", etc. as shown below:

Code: Select all

<?php
$_SESSION["cart"] = array(  "Product_ID" => $_POST['Product_ID'], 
								"short_desc" => $_POST['short_desc'], 
								"style_ID"   => $_POST['style_color'],  
								"price_ID"   => $_POST['qty_price'],  
								"parts"      => $_POST['parts']
								);
?>

Posted: Fri Nov 19, 2004 7:39 am
by peni

Code: Select all

echo $_SESSION["cart"]["Product_ID"];
or what do you mean by "how do i access"?

Posted: Fri Nov 19, 2004 7:52 am
by DudeBori82
But that is just for one product in the cart, how do I increment between products, pulling each product's information.

Posted: Fri Nov 19, 2004 8:03 am
by peni
try to fill the sessvar an other way:

Code: Select all

$_SESSION["cart"][$productId] = array(  "Product_ID" => $_POST['Product_ID'],
                                 "short_desc" => $_POST['short_desc'], 
                                  "style_ID"   => $_POST['style_color'],
                                  "price_ID"   => $_POST['qty_price'],
                                  "parts"      => $_POST['parts']
                                );
then you'll be able to increment the $productId and get one array per product.

p.s. print_r($_SESSION["cart"][1]); will give you information about the second product in the cart.
or echo $_SESSION["cart"][1]["Product_ID"];