13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

628 Chapter 28 Building a Shopping Cart<br />

Listing 28.10 display_cart() Function from output_fns.php—Function That<br />

Formats <strong>and</strong> Prints the Contents of the Shopping Cart<br />

function display_cart($cart, $change = true, $images = 1) {<br />

// display items in shopping cart<br />

// optionally allow changes (true or false)<br />

// optionally include images (1 - yes, 0 - no)<br />

echo "<br />

<br />

Item<br />

Price<br />

Quantity<br />

Total<br />

";<br />

//display each item as a table row<br />

foreach ($cart as $isbn => $qty) {<br />

$book = get_book_details($isbn);<br />

echo "";<br />

if($images == true) {<br />

echo "";<br />

if (file_exists("images/".$isbn.".jpg")) {<br />

$size = GetImageSize("images/".$isbn.".jpg");<br />

if(($size[0] > 0) && ($size[1] > 0)) {<br />

echo "";<br />

}<br />

} else {<br />

echo "&nbsp;";<br />

}<br />

echo "";<br />

}<br />

echo "<br />

".$book['title']."<br />

by ".$book['author']."<br />

\$".number_format($book['price'], 2)."<br />

";<br />

// if we allow changes, quantities are in text boxes<br />

if ($change == true) {<br />

echo "";<br />

} else {<br />

echo $qty;<br />

}<br />

echo "<br />

\$".number_format($book['price']*$qty,2)."

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!