Chapter 1: ColdFusion Tags
131
<CFSET CountVar=Co 1>
The loop index is <CFOUTPUT>#CountVar#</CFOUTPUT>.<BR>
</CFLOOP>
The result of this loop in a browser would look something like:
The loop index is 1.
The loop index is 2.
The loop index is 3.
The loop index is 4.
The loop index is 5.
Looping over a Query
A loop over a query repeats for every record in the query record set. The CFLOOP
results are just like a
CFOUTPUT
. During each iteration of the loop, the columns of the
current row will be available for output. CFLOOP allows you to loop over tags that can
not be used inside CFOUTPUT.
Syntax
<CFLOOP QUERY="query_name"
STARTROW="row_num"
ENDROW="row_num">
QUERY
Required. Specifies the query that will control the loop.
STARTROW
Optional. Specifies the first row of the query that will be included in the loop.
ENDROW
Optional. Specifies the last row of the query that will be included in the loop.
Example 1
The following example shows a CFLOOP looping over a query that works in the same
way as a CFOUTPUT tag using the QUERY attribute:
<CFQUERY NAME="MessageRecords"
DATASOURCE="cfsnippets">
SELECT * FROM Messages
</CFQUERY>
<CFLOOP QUERY="MessageRecords">
<CFOUTPUT>#Message_ID#</CFOUTPUT><BR>
</CFLOOP>
Example 2
CFLOOP also provides iteration over a recordset with dynamic starting and stopping
points. Thus you can begin at the tenth row in a query and end at the twentieth. This
mechanism provides a simple means to get the next n sets of records from a query.
Summary of Contents for COLDFUSION 4.5-CFML LANGUAGE
Page 1: ...Allaire Corporation CFML Language Reference ColdFusion 4 5...
Page 207: ...Chapter 1 ColdFusion Tags 183 CFCATCH CFTRY BODY HTML...
Page 224: ...200 CFMLLanguageReference CFOUTPUT P Text within CFOUTPUT is always shown CFOUTPUT BODY HTML...
Page 336: ...312 CFMLLanguageReference CFIF BODY HTML...
Page 404: ...380 CFMLLanguageReference DE It is morning CFOUTPUT P BODY HTML...
Page 413: ...Chapter 2 ColdFusion Functions 389 Customer BalanceDue BR CFOUTPUT CFIF BODY HTML...
Page 483: ...Chapter 2 ColdFusion Functions 459 CFOUTPUT CFLOOP BODY HTML...
Page 584: ...560 CFMLLanguageReference...
Page 594: ...570 CFMLLanguageReference...