Programming instructions
Enhancing the Trip Maintenance application 123
<cfelseif IsDefined("Form.btnLast.X")>
ORDER BY tripID DESC
</cfif>
</cfquery>
<cfif TripQuery.RecordCount is 1>
<cflocation url="tripdetail.cfm?ID=#TripQuery.tripID#">
<cfelese>
<cflocation url="tripdetail.cfm?ID=#Form.RecordID#">
</cfif>
Reviewing the code
The following table describes the code used to process the navigation button requests:
Code Explanation
<cfquery
name="TripQuery"
dataSource="compasstravel" 
maxRows=1>
The cfquery tag identifies that a query 
named "TripQuery" will be 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 if the user pressed 
a navigation button on the browse page. 
The X property is checked since the 
buttons on the detail page use image 
type HTML input tags. The X property is 
a mouse offset that gets sent when you 
click a graphic button.
The WHERE and ORDER BY clauses 
will vary depending on the navigation 
button clicked by the user.
<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 if the query 
returned a row to display. If it did, use that 
tripID to form a URL to navigate to 
using the cflocation tag. If the query 
returned no rows, navigate back to the 
detail page with current record id passed 
in the hidden form variable RecordID.










