Here is a simple cart, but should give you the idea.
Cheers!
-J
<?
switch($action) {
# Add to cart
case 'add':
$_SESSION['cart'][$id] = array('name'=>$name,'price'=>$price,'qty'=>$qty);
break;
# Remove from cart
case 'remove':
# Remove item
unset($_SESSION['cart'][$id]);
break;
}
# Show cart contents if any
if (count($_SESSION[cart]) > 0) {
print "Cart contents:";
foreach($_SESSION[cart] as $id => $value) {
print "<li> $value[qty] $value[name] (@\$$value[price])<br>";
$total += $value[price] * $value[qty];
}
print "Total: \$$total<hr><br>";
}
# a product
$id = 101; $name = 'beer'; $price = '3.15';
?>
<form action="<?=$PHP_SELF?>">
<p>Qty: <input type="textbox" name="qty" size=3 value="1"><br>
Product: <?=$name?><br>
Price: $<?=$price?> NZD<br>
<input type="radio" name="action" value="add" checked> Add
<input type="radio" name="action" value="remove"> Remove
<input type="submit" value="OK">
</p>
<input type="hidden" name="id" value="<?=$id?>">
<input type="hidden" name="name" value="<?=$name?>">
<input type="hidden" name="price" value="<?=$price?>">
</form>
?>
On Sun, 12 May 2002 06:02:39 +1200, Dave Carrera wrote:
> Hi All
>
>
>
> Can someone breakdown the logic of adding and subtracting products to a
> shopping cart using sessions.
>
>
>
> I can't quite get the logic so something in plain English would help
> very much.
>
>
>
> Any helpful advice, pointers or even code examples are very much
> appreciated.
>
>
>
> Thank you fully in advance for any help you may give.
>
>
>
> Dave C
--
.--- .- ... --- -. / -- --- .-. . .... --- ..- ... .
Jason Morehouse
[EMAIL PROTECTED]
Netconcepts LTD
Auckland, New Zealand
- Linux: because rebooting is for adding hardware.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php