User Guide

72 Chapter 6: Lesson 2: Writing Your First ColdFusion Application
</cfquery>
<html>
<head>
<title>Trip Maintenance - Search Results</title>
</head>
<body>
<img src="images/tripsearchresults.gif">
<table border="0" cellpadding="3" cellspacing="0">
<tr bgcolor="Gray">
<td>Trip Name
</td>
<td>Location
</td>
<td>Departure Date
</td>
<td>Return Date
</td>
<td>Price
</td>
</tr>
<cfoutput query="TripResult">
<tr>
<td>#tripName#
</td>
<td>#tripLocation#
</td>
<td>#departureDate#
</td>
<td>#returnDate#
</td>
<td>#price#
</td>
</tr>
</cfoutput>
</table>
</body
Reviewing the code
The following table describes the code used to build the tripLocation WHERE subclause:
Note that the preceding code only builds the tripLocation subclause. In the following exercise
you will add code for the other two queryable columns, departureDate and price.
Code Explanation
<cfset WhereClause = " 0=0 ">
The cfset tag initializes the WhereClause
variable to hold the WHERE clause to be
constructed. The initial value is set to "0=0", so
that the WHERE clause has at least one
subclause in case the user enters no search
criteria.
<cfif Form.tripLocationValue GT "">
The cfif tag tests to see if user entered
anything in the Value input box for tripLocation
criterion.
SELECT tripName, tripLocation,
departureDate, returnDate, price, tripID
FROM trips
WHERE #PreserveSingleQuotes(WhereClause)#
SQL query to execute. PreserveSingleQuotes
ColdFusion function ensures that quotation
marks will passed to the database server as
intended.