Web Applications  
Advanced Search



TOC


Creating an Advanced Search Master/Detail Page Set

Just as when you created a Product guide, advanced search will require a Master page and a Detail page. In addition to these two PHPs, an HTML document is used for the advanced search form.

  1. Add an "Advanced Search" link near the Search Box in your site's pages. This link connects to /382/html/adv-search.html in your site's root folder.

    Dreamweaver Command: Edit Find and Replace .. Entire Current Local Site.

    You can change something on all your site pages simultaneously by using this command. E.g., add a link at the same spot in all your pages.

    This command can save you a lot of work: you do not have to edit multiple pages individually.

    Caveat: Since global changes cannot be undone, practice using this command by making small changes first.


  2. adv-search.html. This document displays your advanced search form.

    The form uses method="Get" and action="../php/adv-srch-master.php".

    Add an HTML element that supports search based on three categories of search. A movie site could use Cast, Director, Rating. HTML elements that support this kind of search would be a select element (drop-down list) or a set of radio buttons.

    When the user selects Cast as the category, the user would enter the name of someone in the cast, in the textbox.

    The name of the HTML element plays a significant role in the search. For example, srchCat, is a good name to use for the radio button names or the select name.

    If the user selected Cast and entered "Bogart", the URL parameters would be srchCat=Cast&srchTarget=Bogart

    For this search to succeed, your database would need a table that has a Cast field.

    The value attributes must match exactly the table field names in your database. The following example is correct for a Movie table with fields named movTitle, movDirector and movCast: <select name="srchCat" > <option value ="movTitle">Title</option> <option value ="movDirector">Director</option> <option value ="movCast">Cast</option> </select> The same rule applies for radio buttons: the value must be a field name in your Product table.

    ¡ Caution ! Do not use any blanks, special characters, or reserved names as field names in a table, as they will create errors in the SQL query you write for the recordset.

    Table Field Names to Avoid for Successful SQL Queries: MovieTitle is OK, but Movie Title is not; orderDate is OK, but Date is not.

  3. Open a new php for the search master page (save it /382/php/adv-srch-master.php).

    Follow the steps in How to Create an SQL Query with Search Parameters in SQL Variables.

  4. Build the master and detail pages in one operation, using the Master Detail Page Set data object.

    In Design view, select Insert > Data Objects > Master Detail Page Set.

    Fill in the dialog fields. In the Link To Detail From pop-up menu, select the column in the recordset that will display a value that also serves as a link to the detail page (e.g., the movie title).

    In the Pass Unique Key pop-up menu, select the column in the recordset containing values identifying the record (e.g., the primary key field).

    In the Detail Page Name box, click Browse and locate the detail page file you created, or enter a name and let the data object create one for you.

    The simplest solution of all: just enter the name of your product guide detail page (product.php).

  5. Customize the layout of the master and detail pages to match your site design.

    Your site now has Advanced Search capability.

Review: How a SELECT List is Submitted as a URL Parameter

If the user selects Title in the following select list, the parameter ?srchCat=title will be appended to the URL for adv-srch-master.asp when the Submit button is clicked. <form name="srchForm" action="../php/adv-srch-master.php" method="GET"> <select name="srchCat"> <option value="">Category</option> <option value="Title">Title</option> <option value="Director">Director</option> <option value="Cast">Actor</option> </select> <input type="submit" value="Search" /> </form>

Debugging Tip: Displaying URL Parameters in the body of an PHP

To verify that a PHP has access to URL parameters, insert the following HTML and PHP statements in the content section of a PHP:
URL parameters: 
srchCategory = 
srchTarget = 
The PHP in the above example can be inserted automatically by placing the cursor immediately following the "=" sign, and then selecting Insert > PHP Objects > URL Parameters. You then add the names of the URL parameters.