Well, ideally you want to store your cart like so...
PHP Code:
<?php
$cart = array(
1 => array(
'name' => 'Foo Biscuits',
'quantity' => 56,
'price' => 1.99
),
2 => array(
'name' => 'Bar Sandwich',
'quantity' => 3,
'price' => 4.99
),
);
You would then add a product like this...
PHP Code:
<?php
$cart[ $_POST['product_id'] ] = array(
'name' => $_POST['product_name']
)
...and iterate over them a bit like...
PHP Code:
<?php
foreach($cart as $id => $product){
printf(
'You have %d of (%d)%s at %f each' . PHP_EOL,
$product['quantity'],
$id,
$product['name'],
$product['price']
);
}
/*
You have 56 of (1)Foo Biscuits at 1.990000 each
You have 3 of (2)Bar Sandwich at 4.990000 each
*/
Bookmarks