<CFLOOP> Tag - ColdFusion


>> Return to ColdFusion Tag Index

The <CFLOOP> tag allows you ...





  <CFLOOP> Comments from Macromedia LiveDocsLiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p76.htm
The CFLOOP logic is tested in the beginning of the loop. This could be considered DO-WHILE logic. It is possible that the routine within the CFLOOP could never be executed.

What tags exist to have the condition tested after the first execution of the routine. I need to always execute the loop at least one time. Can someone help me?

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p76.htm
The code posted by Mike@Jobscience does not work for two reasons:

1) The function reference in the cfloop query attribute must be surrounded by pound signs.
The cfloop tag is treating "getQuery()" as a literal string, and there is no query named getQuery().

2) The cfloop query attribute requires the name of a query, not the query itself.
The getQuery() function returns the query, not its name.
If you fix problem 1, but not problem 2 the page generates a "Complex object types cannot be converted to simple values" error because it is trying to convert the query object to a string.

The following code does work as desired, but the function is not needed, since it just returns a hard-coded value that could be used directly as the cfloop query attribute.
(Note that this version of the code is not optimum CFML, as you can use cfoutput with a query attribute without using a cfloop.)

<cfquery name="myQuery" datasource="cfsnippets">
SELECT FirstName
FROM Employees
</cfquery>

<cffunction name="getQuery">
<cfreturn "myQuery"> <!--- A previously created query --->
</cffunction>
<cfoutput>
<cfloop query="#getQuery()#">
#FirstName#<br>
</cfloop>
</cfoutput>

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p76.htm
I have noticed that looping through a query required a direct reference to the query variable rather than a returned refernce, such as:

<cffunction name="getQuery">
<cfreturn variables.myQuery> <!--- A previously created query --->
</cffunction>

<cfloop query="getQuery()">
--- output
</cfloop>

This does not work, at least not that I have been able to make it happen.

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p76.htm
absolutely, do a google search for 'nested loop coldfusion' and you'll get a few sources or try http://livedocs.macromedia.com/coldfusion/6/Developing_ColdFusion_MX_Applications_with_CFML/arrayStruct4.htm this one explains the use with arrays

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p76.htm
Can I place a loop inside another loop?

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p76.htm
rgates89: LiveDocs does not receive enough traffic to handle questions such as this
effectively. I suggest posting your issue to the online forums:
http://webforums.macromedia.com/coldfusion/ where, I'm sure, you will get
quite a few creative solutions. Also, I tried to send you an e-mail, but it bounced.

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p76.htm
How can I delay a loop for X number of seconds. Let's say I want to query a database over and over again without refreshing the page to check if there's new data in the database, but because I don't want to put too much stress on the database, I only want to do this ever 2 seconds. How is this possible?

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p76.htm
There is an enhancement request (52228) oustanding for a cfcontinue tag.
We will be considering it for a future release.

LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p76.htm
It would be very handy to have a <CFCONTINUE> tag (a familiar programming concept) that continues the loop from the beginning, in the next iteration.



[Top]


Recommended Books

[Top]

Web Sites

[Top]

Copyright © 2003- 2008, Orville Paul Chomer, All Rights Reserved