Specifications

$result = @mysql_query($query);
if (!$result)
return false;
$num_cats = @mysql_num_rows($result);
if ($num_cats ==0)
return false;
$result = mysql_result($result, 0, “catname”);
return $result;
}
After we have retrieved the category name, we can render an HTML header and proceed to
retrieve and list the books from the database that fall into our chosen category, as follows:
$book_array = get_books($catid);
display_books($book_array);
The functions get_books() and display_books() are extremely similar to the
get_categories() and display_categories() functions, so we will not go into them here.
The only difference is that we are retrieving information from the books table rather than the
categories table.
The display_books() function provides a link to each book in the category via the
show_book.php script. Again, each link is suffixed with a parameter. This time around, its the
ISBN for the book in question.
At the bottom of the show_cat.php script, you will see that there is some code to display some
additional functions if an administrator is logged in. We will look at these in the section on
administrative functions.
Showing Book Details
The show_book.php script takes an ISBN as a parameter and retrieves and displays the details
of that book. The code for this script is shown in Listing 25.8.
LISTING 25.8 show_book.phpThis Script Shows the Details of a Particular Book
<?
include (‘book_sc_fns.php’);
// The shopping cart needs sessions, so start one
session_start();
// get this book out of database
$book = get_book_details($isbn);
do_html_header($book[“title”]);
display_book_details($book);
Building a Shopping Cart
C
HAPTER 25
25
B
UILDING A
SHOPPING CART
555
LISTING 25.7 Continued
31 7842 CH25 3/6/01 3:38 PM Page 555