Session Variables as an Array
Posted: Wed Jul 18, 2007 5:39 am
Hi all,
Im doing an assignment for university that requires me to set up a simple shopping cart mechanism.
I have 2 pages currently the items list page, that has items with buttons.
Once the button is clicked the cartaction page is called and I am adding the recieved item name into separate session variables of the name sent as seen below
This is working fine because each sessionvariable takes the name of the item. Then if the item is added again the value of the session variable is incremented.
Is there a better way of doing this using an array in the session variable. I not quite sur eon how this would work.
Thanks
Jamie
Im doing an assignment for university that requires me to set up a simple shopping cart mechanism.
I have 2 pages currently the items list page, that has items with buttons.
Once the button is clicked the cartaction page is called and I am adding the recieved item name into separate session variables of the name sent as seen below
Code: Select all
$item = $_REQUEST['item'];
//echo $item;
switch ($item) {
case "coppercasserole":
$HTTP_SESSION_VARS['coppercasserole'] = $HTTP_SESSION_VARS['coppercasserole'] + 1;
// echo "copperCasserole =".$HTTP_SESSION_VARS['coppercasserole'];
break;
case "coppersaucepan":
$HTTP_SESSION_VARS['coppersaucepan'] = $HTTP_SESSION_VARS['coppersaucepan'] + 1;
// echo "coppersaucepan =".$HTTP_SESSION_VARS['coppersaucepan'];
break;
case "coppersaute":
$HTTP_SESSION_VARS['coppersaute'] = $HTTP_SESSION_VARS['coppersaute'] + 1;
// echo "coppersaute =".$HTTP_SESSION_VARS['coppersaute'];
break;
}Is there a better way of doing this using an array in the session variable. I not quite sur eon how this would work.
Thanks
Jamie