System information

82 Chapter 7: Lesson 4: Building Dynamic Queries
3.
Verify that the other criteria (departure date and price) are not taken into consideration yet as
follows:
a
Click the Back button in the browser to return to the Trip Search page.
b
In the Departure Date drop-down list box, select Before, enter 1/1/1900 as the date, and
select Smaller Than 0 for the price.
Either of these conditions would produce a results page with no rows.
c
Click the Search button.
The Trip Search Results page should be identical to the one in Step 2, because the code to
build the WHERE clause in the Trip Search Results page does not include departure date
and price.
Exercise 5: Enabling the departure and price criteria on the Trip
Search form
In this exercise, you will modify the Trip Search Results page to add the criteria needed for the
departure and price query.
To enable the departure and price criteria:
1.
Open the gettrips.cfc file.
2.
In the getTripsFromForm method, position the pointer before the cfquery code block.
3.
To build the departureDate WHERE subclause, enter or copy and paste the code in the
following table immediately before the
cfquery code block:
For this database Enter this code
(Windows users)
Microsoft Access
database file
<!--- Build subclause for departureDate --->
<cfif Form.departureValue GT "">
<cfif Form.departureOperator EQ "EQUALS">
<cfset WhereClause = WhereClause & " and departureDate = " &
CreateODBCDate(Form.departureValue)>
<cfelseif Form.departureOperator EQ "AFTER">
<cfset WhereClause = WhereClause & " and departureDate > " &
CreateODBCDate(Form.departureValue)>
<cfelseif Form.departureOperator EQ "BEFORE">
<cfset WhereClause = WhereClause & " and departureDate < " &
CreateODBCDate(Form.departureValue)>
</cfif>
</cfif>
(UNIX users)
PointBase database
file
<!--- Build subclause for departureDate --->
<cfif Form.departureValue GT "">
<cfif Form.departureOperator EQ "EQUALS">
<cfset WhereClause = WhereClause & " and departureDate = Date '" &
Form.departureValue & "'">
<cfelseif Form.departureOperator EQ "AFTER">
<cfset WhereClause = WhereClause & " and departureDate > Date '"
& Form.departureValue & "'">
<cfelseif Form.departureOperator EQ "BEFORE">
<cfset WhereClause = WhereClause & " and departureDate < Date '" &
Form.departureValue & "'">
</cfif>
</cfif>