Searching and Browsing
This section describes the searching and browsing module in the winestore. As the scripts are complex, we've divided the discussions into three parts: a short description of the search criteria input form; a discussion of the SQL query used to retrieve matching wines; and, an longer overview of the code that produces the browsable results.
Search Criteria Form
Example 20-1 lists
the search input criteria search/searchform.php
script. The script is a straightforward use of the
winestoreFormTemplate
class
discussed in Chapter 16. It
allows users to choose a region and a wine type to browse, and uses
the winestoreFormTemplate::selectWidget(
) method to present these as drop-down lists.
Example 20-1. Thesearch/searchform.php script that displays a search criteria entry form
<?php // This is the script that allows the to search and browse wines, and // to select wines to add to their shopping cart require_once "../includes/template.inc"; require_once "../includes/winestore.inc"; set_error_handler("customHandler"); session_start( ); // Takes <form> heading, instructions, action, formVars name, and // formErrors name as parameters $template = new winestoreFormTemplate("Search", "Choose regions and wine types to browse.", S_SEARCH, "searchFormVars", NULL, "GET"); $connection = DB::connect($dsn, true); if (DB::isError($connection)) trigger_error($connection->getMessage( ), E_USER_ERROR); // Create the drop-down search widgets for the page // Load the regions from the ...
Get Web Database Applications with PHP and MySQL, 2nd Edition 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.