Specifications
output_fns.php, which is included here as Listing 25.10. Although it is a display function, it
is reasonably complex, so we include it here.
LISTING 25.10 display_cart() Function from output_fns.php—This Function Formats and
Prints the Contents of the Shopping Cart
function display_cart($cart, $change = true, $images = 1)
{
// display items in shopping cart
// optionally allow changes (true or false)
// optionally include images (1 - yes, 0 - no)
global $items;
global $total_price;
echo “<table border = 0 width = 100% cellspacing = 0>
<form action = show_cart.php method = post>
<tr><th colspan = “. (1+$images) .” bgcolor=\”#cccccc\”>Item</th>
<th bgcolor=\”#cccccc\”>Price</th><th bgcolor=\”#cccccc\”>Quantity</th>
<th bgcolor=\”#cccccc\”>Total</th></tr>”;
// display each item as a table row
foreach ($cart as $isbn => $qty)
{
$book = get_book_details($isbn);
echo “<tr>”;
if($images ==true)
{
echo “<td align = left>”;
if (file_exists(“images/$isbn.jpg”))
{
$size = GetImageSize(“images/”.$isbn.”.jpg”);
if($size[0]>0 && $size[1]>0)
{
echo “<img src=\”images/”.$isbn.”.jpg\” border=0 “;
echo “width = “. $size[0]/3 .” height = “ .$size[1]/3 . “>”;
}
}
else
echo “ ”;
echo “</td>”;
}
echo “<td align = left>”;
echo “<a href = \”show_book.php?isbn=”.$isbn.”\”>”
.$book[“title”].”</a> by “.$book[“author”];
Building a Shopping Cart
C
HAPTER 25
25
B
UILDING A
SHOPPING CART
561
31 7842 CH25 3/6/01 3:39 PM Page 561










