Help with session vairables (part II)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DudeBori82
Forum Commoner
Posts: 26
Joined: Thu Nov 18, 2004 10:09 am
Location: Florida

Help with session vairables (part II)

Post 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']
								);
?>
peni
Forum Commoner
Posts: 34
Joined: Thu Nov 18, 2004 1:15 pm

Post by peni »

Code: Select all

echo $_SESSION["cart"]["Product_ID"];
or what do you mean by "how do i access"?
DudeBori82
Forum Commoner
Posts: 26
Joined: Thu Nov 18, 2004 10:09 am
Location: Florida

Post by DudeBori82 »

But that is just for one product in the cart, how do I increment between products, pulling each product's information.
peni
Forum Commoner
Posts: 34
Joined: Thu Nov 18, 2004 1:15 pm

Post 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"];
Post Reply