Can I use a While Loop on a session array?
What I mean is, can I do this, but for an array result instead of a mysql query result?
while ($row = mysql_fetch_array ($result)) {
echo 'output goes here';
}
How would I do this for a session array that looks like this? I need to get the $sessID for each instance of the shopping cart session.
$_SESSION['cart'][$sessID] = array ('quantity' => 1, 'price' => $prodPrice, 'prodName' => $prodName, 'handle' => $handle);
There is a good chance that I'm actually making this very difficult for myself. If any one has a better idea of how to do the following, I would love to hear it! Thanks...
I am building a php/mysql shopping cart for a cricket website. When the website user adds a cricket bat to the shopping cart they must select some options:
Bat size, Handle size, Bat Edges, Bat Weight, Etc...
There are between 6 and 10 options depending on the chosen cricket bat.
I add the details to the shopping cart session like this:
$sessID = uniqid();
$prodID = (int) $_POST['prodID'];
$prodName = $_POST['prodName'];
$prodPrice = $_POST['prodPrice'];
$size = $_POST['size'];
$handle = $_POST['handle'];
$weight = $_POST['weight'];
$edges = $_POST['edges'];
$_SESSION['cart'][$sessID] = array ('quantity' => 1, 'price' => $prodPrice, 'prodName' => $prodName, 'handle' => $handle);
On the viewcart.php page I intend on outputting the price and product name from the shopping cart arrays.
The problem is, I don't know how to set a while loop for all the instances of $sessID?
Any thoughts on this would be greatly appreciated.
Thanks