4.4. Building the Online Catalog Application Script

The catalog application has one main script. The script is organized into two basic sections: one section that displays the index page and one that displays the products page. The index page displays when the application first runs, before any buttons have been clicked. When the user clicks a button, the script displays a Web page dependent on which button was pushed. The following is an overview of the structure of the script:

if (Button)

  The Product button was pushed,
      1 Test whether a category was selected. If
        not, redisplay the index page.
      2 Display the products page.

  The Product button was not pushed,
      1 Display the index page.

Listing 4-3 shows the code for the online catalog application script.

Example 4.3. The Online Catalog Application Script
<?php
 /* Program: Catalog.php
  * Desc:    Displays a catalog of products. Displays two
  *          different pages: an index page that shows
  *          categories and a product page that is displayed
  *          when the customer selects a category.
  */
include("dbstuff.inc");                                                   →8
$n_per_page = 2;                                                          →9
if(isset($_POST['Products']))                                               →10
{
  if(!isset($_POST['interest']))                                            →12
  {
    header("location: Catalog_furniture.php");
    exit();
  }
  else                                                                      →17
  {
    if(isset($_POST['n_end']))                                              →19
    {
      if($_POST['Products'] == "Previous")                                  →21
      {
        $n_start = $_POST['n_end']-($n_per_page)-1;
      }
      else                                                                  →25
      {
        $n_start = $_POST['n_end'] + 1;
      }
    }
else                                                                    →30
    {
      $n_start = 1;
    }
    $n_end = $n_start + $n_per_page - 1;                                    →34 $cxn = mysqli_connect($host,$user,$password,$database); ...

Get PHP & MySQL® Web Development All-in-One Desk Reference for Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.