Specifications

LISTING 25.9 show_cart.phpThis Script Controls the Shopping Cart
<?
include (‘book_sc_fns.php’);
// The shopping cart needs sessions, so start one
session_start();
if($new)
{
//new item selected
if(!session_is_registered(“cart”))
{
$cart = array();
session_register(“cart”);
$items = 0;
session_register(“items”);
$total_price = “0.00”;
session_register(“total_price”);
}
if($cart[$new])
$cart[$new]++;
else
$cart[$new] = 1;
$total_price = calculate_price($cart);
$items = calculate_items($cart);
}
if($save)
{
foreach ($cart as $isbn => $qty)
{
if($$isbn==”0”)
unset($cart[$isbn]);
else
$cart[$isbn] = $$isbn;
}
$total_price = calculate_price($cart);
$items = calculate_items($cart);
}
do_html_header(“Your shopping cart”);
if($cart&&array_count_values($cart))
display_cart($cart);
else
{
Building a Shopping Cart
C
HAPTER 25
25
B
UILDING A
SHOPPING CART
559
31 7842 CH25 3/6/01 3:39 PM Page 559