Programming instructions
Using a web page to list trips 67
Reviewing the code
The following table describes the code used to build the query:
Exercise: enhancing the query
In this exercise you will improve the Trip List page to make it easier for the Compass
Travel agents to locate trips. You must make the following improvements:
• Sort the trip names in alphabetic order.
• Display the departure date, return date, and price for each trip.
• Develop a Budget Trip List report that identifies trips that are priced $1500 or less.
To enhance the trip listing query to meet these new requirements, you will modify the
query you created in the previous exercise.
Follow these steps to enhance the query to meet the new requirements. Display the
triplisting.cfm page in the browser after each step to ensure the corresponding
requirement was met.
To enhance the query results:
1 To sort the trip names in alphabetical order in the triplisting.cfm page, modify the
SQL SELECT statement within the
cfquery tags as follows:
SELECT tripName FROM trips ORDER BY tripName
2 To display the departure, return date, and price for each trip, modify the same SQL
statement.
a Modify the SQL SELECT statement, as follows:
SELECT tripName, departureDate, returnDate, price
FROM trips
ORDER BY tripName
b Change the output block (the code immediately preceding the </cfoutput> tag)
from just
#tripName# to include all three selected fields, as follows:
#tripName# departs: #departureDate# returns: #returnDate# price:
#price#<BR>
Code Explanation
<cfquery name="TripResult"
datasource="CompassTravel">
ColdFusion query named "TripResult". Submits any SQL
statement between the cfquery start and end tags to the
data source specified in the datasource attribute.
SELECT tripName FROM trips
SQL SELECT statement to retrieve all tripName(s) from
the trips table.
<cfoutput query="TripResult">
#tripName#<BR></cfoutput>
Output code block. Displays the value of the column
tripName for each row in the result set from the
"TripResult" query.