The user interface has been simplified in Dreamweaver and later. As a result, you may not find some of the options described in this article in Dreamweaver and later. For more information, see this article.
You can use Dreamweaver to build a set of pages to let users search your database and view the search results.
In most cases, you need at least two pages to add this feature to your web application. The first page is a page that contains an HTML form in which users enter search parameters. Although this page doesn’t do any actual searching, it is referred to as the search page.
The second page you need is the results page, which performs most of the work. The result’s page does the following tasks:
Reads the search parameters submitted by the search page
Connects to the database and searches for records
Builds a recordset with the records found
Displays the contents of the recordset
Optionally, you can add a detail page. A detail page gives users more information about a particular record on the results page.
If you have only one search parameter, Dreamweaver lets you add search capabilities to your web application without using SQL queries and variables. Simply design your pages and complete a few dialog boxes. If you have more than one search parameter, you need to write a SQL statement and define multiple variables for it.
Dreamweaver inserts the SQL query in your page. When the page runs on the server, each record in the database table is checked. If the specified field in a record meets your SQL query conditions, the record is included in a recordset. The SQL query in effect builds a recordset containing only the search results.
For example, field sales staff might have information about customers in a certain area who have incomes above a certain level. In a form on a search page, the sales associate enters a geographical area and a minimum income level, and then clicks the Submit button to send the two values to a server. On the server, the values are passed to the results page’s SQL statement, which then creates a recordset containing only customers in the specified area with incomes above the specified level.
A search page on the web typically contains form fields in which the user enters search parameters. At minimum, your search page must have an HTML form with a Submit button.
To add an HTML form to a search page, complete the following procedure.
An empty form is created on the page. You might need to enable Invisible Elements (View > Visual Aids > Invisible Elements) to see the form’s boundaries, which are represented by thin red lines.
Form objects include text fields, menus, options, and radio buttons. You can add as many form objects as you want to help users refine their searches. However, keep in mind that the greater the number of search parameters on the search page, the more complex your SQL statement will be.
Next, you’ll tell the form where to send the search parameters when the user clicks the Submit button.
GET sends the form data by appending it to the URL as a query string. Because URLs are limited to 8192 characters, don’t use the GET method with long forms.
POST sends the form data in the body of a message.
Default uses the browser’s default method (usually GET).
The search page is done.
When the user clicks the form’s Search button, the search parameters are sent to a results page on the server. The results page on the server, not the search page on the browser, is responsible for retrieving records from the database. If the search page submits a single search parameter to the server, you can build the results page without SQL queries and variables. You create a basic recordset with a filter that excludes records that don’t meet the search parameter submitted by the search page.
If you have more than one search condition, you must use the advanced Recordset dialog box to define your recordset (see Build an advanced results page ).
If you don’t have a results page yet, create a blank dynamic page (File > New > Blank Page).
If the advanced dialog box appears instead, switch to the simple dialog box by clicking the Simple button.
The connection should be to a database containing data you want the user to search.
In a single-parameter search, you can search for records in only a single table. To search more than one table at a time, you must use the advanced Recordset dialog box and define a SQL query.
You should include only the columns containing information you want to display on the results page.
Leave the Recordset dialog box open for now. You’ll use it next to retrieve the parameters sent by the search page and create a recordset filter to exclude records that don’t meet the parameters.
For example, if the value sent by the search page is a city name, select the column in your table that contains city names.
The search page uses either a form variable or a URL parameter to pass information to the results page.
The name of the object doubles as the name of the form variable or URL parameter. You can get the name by switching to the search page, clicking the form object on the form to select it, and checking the object’s name in the Property inspector.
For example, suppose you want to create a recordset that includes only adventure trips to a specific country. Assume you have a column in the table called TRIPLOCATION. Also assume the HTML form on your search page uses the GET method and contains a menu object called Location that displays a list of countries. The following example shows how your Filter section should look:
The test value simulates the value that would otherwise have been returned from the search page. Click OK to close the test recordset.
A server-side script is inserted on your page that checks each record in the database table when it runs on the server. If the specified field in a record meets the filtering condition, the record is included in a recordset. The script builds a recordset that contains only the search results.
The next step is to display the recordset on the results page. For more information, see Display the search results .
If the search page submits more than one search parameter to the server, you must write a SQL query for the results page and use the search parameters in SQL variables.
If you have only one search condition, you can use the simple Recordset dialog box to define your recordset (see Build a basic results page ).
The advanced dialog box has a text area to enter SQL statements. If the simple dialog box appears instead, switch to the advanced dialog box by clicking the Advanced button.
The connection should be to a database containing data you want the user to search.
Make sure the statement includes a WHERE clause with variables to hold the search parameters. In the following example, the variables are called varLastName and varDept:
SELECT EMPLOYEEID, FIRSTNAME, LASTNAME, DEPARTMENT, EXTENSION FROM EMPLOYEE ¬ WHERE LASTNAME LIKE 'varLastName' ¬ AND DEPARTMENT LIKE 'varDept'
In the following ASP example, the HTML form on the search page uses the GET method and contains one text field called LastName and another called Department:
In ColdFusion, the run-time values would be #LastName# and #Department#. In PHP, the run-time values would be $_REQUEST["LastName"] and $_REQUEST["Department"].
The default values simulate the values that would otherwise have been returned from the search page. Click OK to close the test recordset.
The SQL query is inserted in your page.
The next step is to display the recordset on the results page.
After creating a recordset to hold the search results, you must display the information on the results page. Displaying the records can be a simple matter of dragging individual columns from the Bindings panel to the results page. You can add navigation links to move forward and backward through the recordset, or you can create a repeating region to display more than one record on the page. You can also add links to a detail page.
For more information on methods of displaying dynamic content on a page other than displaying results in a dynamic table, see Displaying database records.
Your set of search and results pages can include a detail page to display more information about specific records on the results page. In this situation, your results page also doubles as the master page in a master-detail page set.
You can create a link that opens a related page and that passes existing parameters to that page. The server behavior is only available when using the ASP server model.
Before adding a Go To Related Page server behavior to a page, make sure the page receives form or URL parameters from another page. The job of the server behavior is to pass these parameters to a third page. For example, you can pass search parameters received by a results page to another page and save the user from entering the search parameters again.
Also, you can select text or an image on the page to serve as the link to the related page, or you can position your pointer on the page without selecting anything, and the link text is inserted.
If the current page submits data to itself, enter the current page’s file name.
When the new link is clicked, the page passes the parameters to the related page using a query string.