Hi all,
Having some trouble with storing multi dimensional session arrays.
This what i have so far:
<form action="addtocart_test.php" method="post">
<INPUT name="prod_id" type="hidden" value="<? echo $_GET['prod_id'] ?>">
<INPUT name="qty" type="hidden" value="1">
<INPUT type="submit" name="AddToCart" value="Add to Cart">
</form>
The addtocart.php script looks like:
session_start();
$cart = array($_POST['prod_id'], $_POST['qty']);
$count_array = count($cart);
$_SESSION['cart'] = $cart;
for ($i = 0; $i < $count_array; $i++)
{
echo $_SESSION['cart'][$i] . ", ";
}
echo "<br>";
At the moment this successfully outputs the 'prod_id' and 'qty'.
Now, what i want to be able to do is if the same prod_id is passed, lets say 4 then it will out put something along the lines of:
4, 1,
4, 1,
I want it to output all of them even if they contain the same prod_id, at the moment it just putputs one.
Do i have to add another dimesion to the existing array?
Or is there another way to do this, maybe add a unigue number at the start of the array...i'm not sure.
This is the basis of a shopping cart script.
Cheers,
micmac