![]() ![]() ![]() |
||
|
To build the Trip Detail page, you do the following:
<cfinvoke component="cfdocs.getting_started.my_app.components.displaytripdetail" method="getTripDetails" returnvariable="tripDetails"> </cfinvoke>
<cfcomponent> <cffunction name="getTripDetails" access="public" returntype="query"> <cfset var tripDetails = "" > <cfquery name="tripDetails" datasource="CompassTravel" maxrows=1> SELECT * FROM trips <cfif IsDefined("URL.ID")> WHERE tripID = #URL.ID# </cfif> </cfquery> <cfreturn tripDetails> </cffunction> </cfcomponent>
You can use the Dreamweaver Extensions to build the CFC query.
cfquery
code block by adding the highlighted text:
<cfquery name="tripDetails" datasource="CompassTravel" maxrows=1> SELECT * FROM trips <cfif IsDefined("URL.ID")> WHERE tripID = #URL.ID# </cfif> </cfquery>
cfoutput
code after the cfinvoke
code block:
<cfoutput query="TripDetails"> <img src="images/tripmaintenance.gif"> <table> <tr> <td valign="top"> Trip Name: </td> <td> #tripName# </td> </tr> <tr> <td valign="top"> Description: </td> <td> #tripDescription# </td> </tr> <tr> <td valign="top"> Location: </td> <td> #tripLocation# </td> </tr> <tr> <td valign="top"> Departure Date: </td> <td> #departureDate# </td> </tr> <tr> <td valign="top"> Return Date: </td> <td> #returnDate# </td> </tr> <tr> <td valign="top"> Price: </td> <td> #price# </td> </tr> <tr> <td valign="top"> Base Cost: </td> <td> #baseCost# </td> </tr> <tr> <td valign="top"> Trip Leader: </td> <td> #tripLeader# </td> </tr> <tr> <td valign="top"> Number People: </td> <td> #numberPeople# </td> </tr> <tr> <td valign="top"> Deposit Required: </td> <td> #depositRequired# </td> </tr> <tr> <td valign="top"> Photo File: </td> <td> #photo# </td> </tr> </table> </cfoutput>
<cfoutput query = "TripQuery">
line:
<html><head> <title> Trip Maintenance - View Record </title> </head> <body>
</body> </html>
http://localhost/cfdocs/getting_started/my_app/tripdetail.cfm?ID=24
Note: If you are using the built-in ColdFusion server, enter localhost:8500
instead of localhost
.
The following figure shows the expected result:
The following table describes the ColdFusion code that you use to build the Trip Detail page:
Code |
Explanation |
---|---|
<cfcomponent> <cffunction name="getTripDetails" access="public" returntype="query"> ... <cfreturn tripDetails> </cffunction> </cfcomponent> |
The |
<cfquery name="TripQuery" |
The |
<cfif IsDefined("URL.ID")> WHERE tripID = #URL.ID# </cfif> |
The URL.ID specifies a parameter that you can include in the URL that requests this page. If the ID parameter is passed within the URL, it is used in the SQL query to identify the |
As you did in this exercise, you can build comprehensive database query applications using CFML and dynamic SQL. To further test the new Trip Detail page that you created, you will link it to the search facility that you built in Lesson 4: Building Dynamic Queries. However, before you link that search facility, you must understand a potential security risk using dynamic SQL. The following exercise describes this risk and how to avoid it.
|
||
![]() ![]() ![]() |