Exercise 1: Enabling users to browse trip details
125
Limiting the number of result rows
Each of the SQL statements in the preceding table returns 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, because only the initial row in the result set appears on the Trip Detail page.
ColdFusion provides the
maxRows
attribute for 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.
To build the Navigation Action page:
1.
Create a blank file.
2.
Enter the following code in the blank file:
<!---
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")>
WHERE tripID > #Form.RecordID#
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>
3.
Save the file as navigationaction.cfm in the my_app directory.
Note:
In previous lessons, you adhered to good coding practices by putting queries in ColdFusion
components. To optimize performance, and because the Navigation Action page contains only a
query, the page is a ColdFusion page rather than a CFC. For more information about code reuse, see
Chapter 8, “Creating ColdFusion Elements” in
ColdFusion MX Developer’s Guide
.
Содержание COLFUSION MX 7-GETTING STARTED BUILDING COLDFUSION...
Страница 1: ...COLDFUSION MX7 Getting Started Building ColdFusion MX Applications...
Страница 6: ...6 Contents...
Страница 10: ......
Страница 14: ...14 Chapter 1 Introducing ColdFusion MX...
Страница 38: ...38 Chapter 3 Database Fundamentals...
Страница 40: ......
Страница 58: ...58 Chapter 5 Lesson 2 Configuring Your Development Environment...
Страница 70: ...70 Chapter 6 Lesson 3 Retrieving Data...
Страница 84: ...84 Chapter 7 Lesson 4 Building Dynamic Queries...
Страница 96: ...96 Chapter 8 Lesson 5 Creating a Trip Detail Page...
Страница 102: ...102 Chapter 9 Lesson 6 Creating a Main Application Page...