Once you've defined a recordset for the results pages, you can add a dynamic table to display the search results. By including form objects on the search page in which the user can enter any value, such as the Price text field in the search_advanced.cfm page, you can use two Show Region server behaviors (Show If Recordset Is Not Empty and Show If Recordset Is Empty). The first behavior will display the dynamic table only if the recordset contains records, and the latter behavior will display a message if the user enters a value that's less than the values in the price field in the trips table.
In the first task in this section, you'll add a dynamic table to the results_simple.asp page to display the results using the search parameter submitted on the search_simple.asp page.
In the second task, you'll add a dynamic table, a Show If Recordset Is Not Empty server behavior to display the recordset results using the search parameters submitted from the search_advanced.cfm page, and a Show If Recordset Is Empty server behavior to display a message if no records match the submitted search parameters.
To add a dynamic table to display simple search results:
Choose Insert > Application Objects > Dynamic Data > Dynamic Table to insert a dynamic table. The Dynamic Table dialog appears.
From the Recordset drop-down list, choose the locations recordset (Figure 11.23).
Figure 11.23. Select the locations recordset in the Dynamic Table dialog.
In the Show section, select the Records at a Time radio button. The default setting is 10.
The Repeat Region server behavior that's included in the Dynamic Table application object dynamically adds a row for every record in the recordset, up to the number of rows that you set in the Show field. If more rows are needed to display all the records, an additional page is created and recordset navigation links are automatically added.
In the Border, Cell Padding, and Cell Spacing fields, enter values for the number of pixels for the width of the table border, the padding between the outer border of a cell and its contents, and the space between the cells. You can also use the supplied default values (Figure 11.23).
You may want to edit the names of the column headings to make the table easier for your page visitors to use. You can delete any columns you don't want to include, and change any design features of the table, such as background color, size, or border type.
Click OK to close the dialog and insert the table.
The Dynamic Table application object inserts HTML table code, adds column headings to the first row of table cells using the recordset field names, adds placeholders for the recordset fields to the second row of table cells, and adds a Repeat Region server behavior to display multiple records in the table.
The table now appears in the Design view window. Figure 11.24 shows the first three columns of the table (Location, City, State or Country), but there are a total of five columns. The other two columns are Telephone and Fax.
Figure 11.24. The dynamic table includes column headers and placeholders for dynamic text. The first three columns of the table are shown.
Save the page.
Open the search_simple.asp page. Choose File > Preview in Browser.
Make a selection from the menu and click the Submit button.
View the results in the results_simple.asp page. All five table columns are shown in Figure 11.25.
Figure 11.25. The results page displays cafetownsend locations in Africa when Africa is selected from the menu on the search page.
To add a dynamic table to display advanced search results:
Follow Steps 2 through 6 in the previous task to add a dynamic table using the eventTrips recordset and display the results from the search parameters submitted on the search_advanced.cfm page.
In Design view, select the table.
In the Application panel group, click the Server Behaviors tab to access the Server Behaviors panel.
Click the plus button and select Show Region > Show If Recordset Is Not Empty from the menu (Figure 11.26).
Figure 11.26. Select the Show If Recordset Is Not Empty server behavior from the Server Behaviors menu.
The table will display the recordset results if the recordset contains records.
Type a message on the page to display if the user entered an invalid value for the Price field on the search_advanced.cfm page (Figure 11.27).
Figure 11.27. A no-results message displays if the user enters an invalid value in the price text field on the search page.
Select the message text that you typed in Step 6. On the Server Behaviors panel, click the plus button and select Show Region > Show If Recordset Is Empty from the menu.
This message will display if the recordset does not contain any records. The table will not display in this case.
Save the page. Open search_advanced.cfm and choose File > Preview in Browser.
Select an event from the menu, and enter a number from 1000 to 6000 in the price field. Click the Submit button to view the search results (Figure 11.28). Use the browser Back button to return to the search_advanced.cfm page, and enter 100 in the price field. Your message displays in the browser window (Figure 11.27).
Figure 11.28. The results page displays results for mountain biking trips with a price of $2000 or less.