System information

126 Chapter 11: Lesson 8: Implementing Browsing and Searching
Reviewing the code
The following table describes the code used to process the navigation button requests:
To test the navigation:
1.
View the tripdetail.cfm page from the my_app directory in a browser.
2.
Click the Next Row button.
The Trip Detail page shows information about the second trip.
3.
Click the Previous Row button.
The Trip Detail page shows information about the first trip.
4.
Click the Last Row button.
The Trip Detail page shows information about the last trip.
5.
Click the First Row button.
The Trip Detail page shows information about the first trip.
Code Explanation
<cfquery
name="TripQuery"
dataSource="CompassTravel"
maxRows=1>
The cfquery tag identifies that a query
named TripQuery is executed against
the CompassTravel data source. The
number of rows returned cannot exceed
1 (
maxRows=1).
SELECT tripID FROM trips
The SQL SELECT statement will
always start with “SELECT tripID
FROM trips.”
<cfif IsDefined("Form.btnPrev.X")>
WHERE tripID < #Form.RecordID#
ORDER BY tripID DESC
<cfelseif IsDefined("Form.btnNext.X")>
WHERE tripID > #Form.RecordID#
ORDER BY tripID
<cfelseif IsDefined("Form.btnFirst.X")>
ORDER BY tripID
<cfelseif IsDefined("Form.btnLast.X")>
WHERE tripID > #Form.RecordID#
ORDER BY tripID DESC
</cfif>
</cfquery>
The cfif tag checks whether the user
pressed a navigation button on the
browse page. The
X property is checked
because the buttons on the detail page
use image type HTML input tags. The
X
property is a mouse offset that gets sent
when the user clicks a graphic button.
The WHERE and ORDER BY clauses
vary depending on the navigation button
that the user clicks.
<cfif TripQuery.RecordCount is 1>
<cflocation
url="tripdetail.cfm?RecordID=#TripQuery.tripID#">
<cfelse>
<cflocation
url="tripdetail.cfm?RecordID=#Form.RecordID#">
</cfif>
The cfif tag checks to see whether the
query returned a row to display. If it did,
that
tripID is used to form a URL to
navigate to using the
cflocation tag. If
the query returned no rows, it navigates
back to the detail page with the current
record ID, which passed in the hidden
form variable
RecordID.