Dynamic Associative Arrays and Sessions
Posted: Sun Apr 10, 2011 4:41 am
Probably easiest to explain what I am trying to do, to illustrate the impasse I have came to. I have online store with a number of products. Visitors can click on products, clicking brings details of the product came up in a iframe on the right (with a field to enter the quantity), which can than be added to the shopping cart in a separate iframe below it bottom right by click add product (passed using a different script (the one which I am having issues with)). So each time a product is added to the cart, three dynamic hidden fields are passed via post, which are named "product_name", "unit_quantity" and "unit_price".
So for the shopping cart, I want to incorporate an associative array using the three dynamic fields described above("product_name", "unit_quantity" and "unit_price") within a session so that a number of products can be added (hence using an array rather than a variable).
So shopping cart i have done so far reads:
<?php
session_start();
if (!isset ($product_name) && !empty($product_name))
{
if (!session_is_registered("product_info"))
{
$pos=0;
session_register("pos");
$product_info[$pos]= array ( 'product_name'=>$product_name, 'unit_quantity'=>$unit_quantity,
'product_quantity'=>$unit_quantity * $unit_price);
session_register("product_info");
}
?>
Not sure (as I am new to sessions, how to call the array to the screen). I have read through past threads but have not been able to found anything similar to what I am trying to achieve).
Any hints?
So for the shopping cart, I want to incorporate an associative array using the three dynamic fields described above("product_name", "unit_quantity" and "unit_price") within a session so that a number of products can be added (hence using an array rather than a variable).
So shopping cart i have done so far reads:
<?php
session_start();
if (!isset ($product_name) && !empty($product_name))
{
if (!session_is_registered("product_info"))
{
$pos=0;
session_register("pos");
$product_info[$pos]= array ( 'product_name'=>$product_name, 'unit_quantity'=>$unit_quantity,
'product_quantity'=>$unit_quantity * $unit_price);
session_register("product_info");
}
?>
Not sure (as I am new to sessions, how to call the array to the screen). I have read through past threads but have not been able to found anything similar to what I am trying to achieve).
Any hints?