
112
Chapter 9: Lesson 5: Implementing the Browsing and Maintenance Database Functions
Limiting the number of result rows
Each of the SQL statements in the previous table return a result set of trips rows. The result set
can range
from zero to any number of rows. The
navigation action page must limit the result set
count to 1, since only the initial row in the result set is needed for the Trip Detail page display.
ColdFusion provides the
maxRows
attribute on the
cfquery
tag for this purpose. This attribute
limits the number of result rows returned from the database. To show only a single row at a time
in the Trip Detail page, set
maxRows
to 1.
The navigation action page
To properly build the SQL SELECT statement for previous and next row navigation, you must
know the current
tripID
. This is the reason for using the hidden input tag
RecordID
on the Trip
Detail page. You can then use the form variable
#Form.RecordID#
in the navigation action page
for building the proper test in the WHERE clause of the SQL SELECT statement. The following
code (from navigationaction.cfm) processes the navigation button requests on the Trip Detail
page:
<!---
NAVIGATION BUTTONS --->
<cfquery name="TripQuery" dataSource="compasstravel" maxRows=1>
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")>
ORDER BY tripID DESC
</cfif>
</cfquery>
<cfif TripQuery.RecordCount is 1>
<cflocation url="tripdetail.cfm?ID=#TripQuery.tripID#">
<cfelse>
<cflocation url="tripdetail.cfm?ID=#Form.RecordID#">
</cfif>
Next Row
SELECT tripID FROM trips
WHERE tripID > 6
ORDER BY tripID
Returns the list of all
tripIDs
greater than 6
in ascending (7,8,9...) order.
Last Row
SELECT tripID FROM trips
ORDER BY tripID DESC
Returns the list of all
tripIDs
in descending
(99,98,97...) order.
Navigation button
SQL statement to navigate to
correct trip ID
SQL statement description
Содержание COLDFUSION MX 61-GETTING STARTED BUILDING COLDFUSION...
Страница 1: ...Getting Started Building ColdFusion MX Applications...
Страница 6: ...6 Contents...
Страница 10: ......
Страница 30: ...30 Chapter 2 CFML Basics...
Страница 36: ...36 Chapter 3 Database Fundamentals...
Страница 48: ......
Страница 76: ...76 Chapter 6 Lesson 2 Writing Your First ColdFusion Application...
Страница 134: ...134 Index...