Specifications

$name = get_category_name($catid);
do_html_header($name);
// get the book info out from db
$book_array = get_books($catid);
display_books($book_array);
// if logged in as admin, show add, delete book links
if(session_is_registered(“admin_user”))
{
display_button(“index.php”, “continue”, “Continue Shopping”);
display_button(“admin.php”, “admin-menu”, “Admin Menu”);
display_button(“edit_category_form.php?catid=$catid”, “edit-category”,
“Edit Category”);
}
else
display_button(“index.php”, “continue-shopping”, “Continue Shopping”);
do_html_footer();
?>
This script is very similar in structure to the index page, with the difference being that we are
retrieving books instead of categories.
We start with session_start() as usual, and then convert the category ID we have been
passed into a category name using the get_category_name() function as follows:
$name = get_category_name($catid);
This function looks up the category name in the database. It is shown in Listing 25.7.
L
ISTING 25.7
get_category_name() Function from book_fns.phpThis Function Converts
a Category ID to a Category Name
function get_category_name($catid)
{
// query database for the name for a category id
$conn = db_connect();
$query = “select catname
from categories
where catid = $catid”;
Building Practical PHP and MySQL Projects
P
ART V
554
LISTING 25.6 Continued
31 7842 CH25 3/6/01 3:38 PM Page 554