Hi
I have a session array as such:
$_SESSION['basket'][$_POST['product']] = array('quantity' => $_POST['quantity'], 'productprice' => $_POST['productprice'], 'giftwrap' => '0')
When viewing the cart of a shopping basket I want to allow the user to change a list box value (the list box only has 2 values) for each product. I am stuck and have no idea how to update the giftwrap value of my session array for each basket item which is set to a default value of 0.
My code is below if anyone can help write somethign that will allow me to update the array when I click my update button.
foreach ($_SESSION['basket'] as $k => $v) {
$sql = "SELECT fields FROM table WHERE productid = $k";
$res = mysql_query($sql);
while ($datarow = mysql_fetch_array($res)) {
$productname = stripslashes($datarow['productname']);
$productid = $datarow['productid'];
$noselected = "";
$yesselected = "";
switch($v['giftwrap']) {
case 0:
$noselected = "selected";
break;
case 1:
$yesselected = "selected";
break;
default:
$noselected = "selected";
break;
}
echo " <div id=\"cartitem$k\" class=\"newcartitem\">
<div id=\"remove_coldata\"><input type=\"checkbox\" name=\"removeitem[]\" value=\"$productid\" /></div>
<div id=\"pdata\">$productname $k</div>
<div id=\"qdata\"><input name=\"quantity_".$k."\" type=\"textfield\" value=\"" . $v['quantity'] . "\" /></div>
<div id=\"adata\"><select size=\"1\" name=\"giftwrap[$productid]\">
<option $noselected value=\"0\">No</option>
<option $yesselected value=\"1\">Yes</option>
</select></div>
</div>";
}
mysql_free_result($res);
}
Thank you in advance.
An Amateur.