![]() ![]() ![]() |
||
|
After the user enters the search criteria and submits the form, the results are posted to the Trip Search Results page, as the following figure shows:
The logic contained in the search results page, also known as the action page, invokes the CFC method that builds the SQL SELECT statement contained in a cfquery
tag by using ColdFusion string manipulation. The action page displays the result using the cfoutput
tag.
Note: If you are using Dreamweaver, select Dynamic page in the Category list, and ColdFusion in the Dynamic Page list.
<cfinvoke component="cfdocs.getting_started.my_app.components.gettrips" method="getTripsFromForm" returnvariable="TripResult"> </cfinvoke>
cfinvoke
tag:
<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> </html>
As you have in previous exercises, you can let Dreamweaver generate the code to invoke the method.
returnvariable
to be the name of the query, TripResult, as follows:
returnvariable="TripResult"
The following table describes the code used to build the tripLocation WHERE subclause:
Code |
Explanation |
---|---|
<cfset WhereClause = " 0=0 "> |
The |
<cfif Form.tripLocationValue GT ""> |
|
SELECT tripName, tripLocation, departureDate, returnDate, price, tripID FROM trips WHERE #PreserveSingleQuotes(WhereClause)# |
SQL query to execute. The |
The preceding code only builds the tripLocation subclause. In the following exercise, you will add code for the other two columns that you can query, departureDate and price.
|
||
![]() ![]() ![]() |