
Summary
83
4.
To build the
price
WHERE subclause, enter the following code after the code you entered in
the previous step.
<!--- Build subclause for price--->
<cfif Form.priceValue GT "">
<cfif Form.priceOperator EQ "EQUALS">
<cfset WhereClause = WhereClause & " and price = " & form.priceValue>
<cfelseif Form.priceOperator EQ "GREATER">
<cfset WhereClause = WhereClause & " and price > " & form.priceValue>
<cfelseif Form.priceOperator EQ "SMALLER">
<cfset WhereClause = WhereClause & " and price < " & form.priceValue>
</cfif>
</cfif>
5.
Save the file.
Exercise 6: Testing the revised Trip Search Results page
In this exercise, you will verify that the
price
and
departureDate
are now considered in the
query.
To test the revised Trip Search Results page:
1.
Open the tripsearchform.cfm page in the my_app directory in your browser.
2.
In the Departure Date drop-down list box, select Before
,
enter
1/1/1900
as the date (specify
1900-1-1
on UNIX).
3.
Select Smaller Than, and enter 0 for the price
.
4.
Click the Search button.
Because the departure date is considered in the query, there are no rows returned.
Note:
If you planned to use many more fields as search criteria, the approach used to add
departure date and price criteria to the Trip Search form is not the most elegant solution. A generic
routine to handle WHERE clause string construction based on specific data types could reduce
the code and be a more extensible solution than the one presented here. However, this more
extensible approach is beyond the scope of this tutorial.
Summary
This lesson described how to build a search tool that dynamically builds a WHERE clause of the
SQL SELECT statement using
cfif
and
cfset
tags. To ensure that the SQL statement remains
intact, you used the
PreserveSingleQuotes
CFML function.
In the next lesson
In the next lesson, you will build the Trip Detail page, which will display detailed information
about the currently selected trip.
Содержание COLFUSION MX 7-GETTING STARTED BUILDING COLDFUSION...
Страница 1: ...COLDFUSION MX7 Getting Started Building ColdFusion MX Applications...
Страница 6: ...6 Contents...
Страница 10: ......
Страница 14: ...14 Chapter 1 Introducing ColdFusion MX...
Страница 38: ...38 Chapter 3 Database Fundamentals...
Страница 40: ......
Страница 58: ...58 Chapter 5 Lesson 2 Configuring Your Development Environment...
Страница 70: ...70 Chapter 6 Lesson 3 Retrieving Data...
Страница 84: ...84 Chapter 7 Lesson 4 Building Dynamic Queries...
Страница 96: ...96 Chapter 8 Lesson 5 Creating a Trip Detail Page...
Страница 102: ...102 Chapter 9 Lesson 6 Creating a Main Application Page...