![]() ![]() ![]() |
||
|
Now that you have decided which columns can be queried (tripLocation, departureDate, and price), you can build a simple form that lets the user enter values for each of these fields. If the user enters a value (for example, Boston) for the tripLocation field and leaves the other two fields blank, the search results page constructs the following SQL statement:
SELECT tripName, tripLocation, departureDate, returnDate, price, tripID FROM trips WHERE tripLocation = 'Boston'
When you design the Search Criteria page, you must decide which operators to support for each of the columns you can query. The operators that you use depend on the data type of the SQL column.
For example, suppose the user wants a list of all the trips where the trip location begins with a "B." SQL is well-suited for this type of query. Typical SQL string operators are equals, starts with, contains, and ends with.
However, price is a numeric data type. The user can specify any of the following:
Although many more operators are permissible, for simplification, you can use the following operators for the Compass Travel columns that you can query:
Column to query |
Query operators |
---|---|
tripLocation |
is, begins with |
departureDate |
is, before, after |
price |
is, greater than, less than |
A simple design for a search criteria page presents an operator list and data entry field for each of the columns that you can query. To create the search criteria page, you create an HTML form.
Note: If you are using Dreamweaver, select Dynamic page in the Category list and ColdFusion in the Dynamic Page list.
<html> <head> <title>Trip Maintenance - Search Form</title> </head> <body> <img src="images/tripsearch.gif"> <!--- Search form ---> <form action="tripsearchresult.cfm" method="post"> <table> <!--- Field: tripLocation ---> <tr> <td> Trip Location </td> <td> <select name="tripLocationOperator"> <option value="EQUALS">is <option value="BEGINS_WITH">begins with </select> </td> <td> <input type="text" name="tripLocationValue"> </td> </tr> <!--- Field: departureDate ---> <tr> <td> Departure Date </td> <td> <select name="departureOperator"> <option value="EQUALS">is <option value="BEFORE">before <option value="AFTER">after </select> </td> <td> <input type="text" name="departureValue"> </td> </tr> <!--- Field: price ---> <tr> <td>Price </td> <td> <select name="priceOperator"> <option value="EQUALS">is <option value="GREATER">greater than <option value="SMALLER">smaller than </select> </td> <td> <input type="text" name="priceValue"> </td> </tr> </table> <p> <input type="submit" value="Search"> </form> </body> </html>
The following table describes the search criteria code and its function:
Code |
Explanation |
---|---|
<form action="tripsearchresult.cfm" method="post"> |
Identifies tripsearchresult.cfm as the search action page. Results of user entry are passed to the search action page. |
<select name="tripLocationOperator"> <option value="EQUALS">is <option value="BEGINS_WITH">begins with </select> |
Builds a drop-down list offering the query operators for tripLocation. There must one operator list box for each queryable column. |
<input type="text" name="tripLocationValue"> |
Captures a value to test. There is one text control for each queryable column. |
|
||
![]() ![]() ![]() |