Searching and Browsing

Example 13-3 shows the searching and browsing search.1 script used in the winestore. The script browses wines by selecting a combination of a wine region name and a wine type. For example, the script can browse the Red wines from the Margaret River region. The user can also choose to browse All regions or All wine types. The browsing interface supports Previous and Next page functionality using embedded links, as well as direct access to any page in the results.

The script is based on the browse( ) function discussed in Chapter 5, which is included here renamed as showWines( ) . The showWines( ) function is customized for presenting wine details and has calls to the functions showVarieties( ) and showPricing( ) from the include.inc include file. It also has embedded links to add one or a dozen bottles of the displayed wine to the shopping cart using the cart.3 script discussed in Chapter 11.

The body of the script checks if search criteria have been provided as GET method parameters. If they have, these are used as parameters to the query that retrieves wines. If GET method parameters aren’t provided, the query is configured using any previous search criteria that have been saved as the session variables sessionRegionName and sessionWineType. In either case, the current search criteria are then saved in the session variables for future use. The query string itself is created using the setupQuery( ) function.

After running the query and presenting the ...

Get Web Database Applications with PHP, and MySQL 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.