Sorry it's very spralled out. I managed to get hold of some code to display a multi-dimensional array and I'm just dealing with the 'add products' bit at the moment. I can get the $GET data to be added to an empty cart but then when the page comes back again (ie to add data to the end of the existing cart) it has a problem (I don't think the array is being stored properly in the session variable 'cart'. I think I've just missed out a '&' somewhere but I'm not exactly sure where. Can you use $array[]=$var to add elements to a multi dimensional array?
The line "$newprod=array('1' => &$item);" is just to see whether I could manually add a second item to the array.
Thanks again,
Richard
<?
session_start();
$refer="cart.php";
$HTTP_SESSION_VARS['refer']=$refer;
function displayResultSet($resultset)
{
echo "<BR>\n";
echo "<CENTER>\n";
echo "<TABLE CELLSPACING=5 CELLPADDING=5 BORDER=3 ";
echo "BORDERCOLOR=\"0000FF\" >\n";
echo "<THEAD>\n";
echo "<TR>\n";
$keycount = 0;
//Output each key as a column heading
while (list ($key,$value) = each($resultset[0])) {
$keycount++;
echo "<TH>";
echo $key;
echo "</TH>\n";
}
echo "</TR>\n";
echo "</THEAD>\n";
//Output each value as elements of a table starting a new row
//each time the key number of columns is reached
$rowcount = sizeof ($resultset);
for($rowCounter = 0;
$rowCounter < $rowcount;
$rowCounter++)
{
$valuesarray = array_values($resultset[$rowCounter]);
echo "<TR>\n";
for($colCounter = 0; $colCounter < $keycount; $colCounter++)
{ echo "<TD>\n";
echo " ";
echo $valuesarray[$colCounter];
echo " ";
echo "</TD>\n";
}
}
echo "</TR>\n";
echo "</TABLE>\n";
echo "</CENTER>\n";
echo "<BR>\n";
}
//Remove product
if (isset ($HTTP_GET_VARS['action']) && $HTTP_GET_VARS['action'] == "remove") {
echo "remove";
}
// Add product
if (isset ($HTTP_GET_VARS['action']) && $HTTP_GET_VARS['action'] == "add") {
$prodname = $HTTP_GET_VARS['descrip'];
$prodref = $HTTP_GET_VARS['ref'];
$price = $HTTP_GET_VARS['price'];
$item= array ("Name" => $prodname, "Ref" => $prodref, "Price" => $price);
if (!isset ($HTTP_SESSION_VARS['cart'])) {
echo "cart not defined";
$cart=array('0' => &$item);
$HTTP_SESSION_VARS['cart']=$cart;
}
else
{
$cart = &$HTTP_SESSION_VARS['cart'];
$id = sizeof($cart);
$newprod=array('1' => &$item);
$cart[]= $newprod;
}
}
?>
<html>
<body bgcolor="#ffffff">
<?
if (!isset ($cart) or sizeof($cart)=='0') {
echo "Basket empty";}
else
{
//display basket
displayResultSet($cart);
}
?>
<a href="<? echo $HTTP_SESSION_VARS['refer']; ?>">Continue Shopping</a>
</body>
</html>