ColdFusion Nested Cfloop Bug and Workaround, "outerqueryset.column1" Displays First Record Only

Coldfusion Nested Cfloop or Cfloop within a Cfloop

Coldfusion Cfloop within a cfloop or gives interesting results. I couldn’t believe it was a bug. But looks to be true once tested. Thanks to Blog of Jehiah Czebotar who bailed me out of this issue after looking at it for some time with eyes crossed and debugging.

Here is the summary from Jehiah blog post. Thanks Again Jehiah!

There is a bug in the processing of nested cfloop tags in Macromedia Cfloop ColdFusion MX, as the example below shows. I have developed a workaround for this which is also below.

Example of Problem

1    <cfloop query="outerqueryset">
2        <cfloop query="innerqueryset">
3            <cfoutput>#outerqueryset.column1# #innerqueryset.column1#<br></cfoutput>
4        </cfloop>
5    </cfloop>

outerqueryset.column1 results in the first record's data being displayed regardless of current iteration in the outer loop.


The workaround is to force the display of the current row, by accessing it via array.

1    <cfloop query="outerqueryset">
2        <cfloop query="innerqueryset">
3            <cfoutput>#outerqueryset.column1[outerqueryset.currentrow]# #innerqueryset.column1#</cfoutput>
4        </cfloop>
5    </cfloop

2 Responses to “Coldfusion Nested Cfloop or Cfloop within a Cfloop”

  1. Jehiah

    May 30th, 2008

    you are welcome. I’m glad I was able to help save some time that would have otherwise been spent beating your head against the wall!

  2. Bill

    May 30th, 2008

    Yep I did beat my head against the wall. Than came across your post. Couldn’t believe that the bug still existed in the latest version. Is this a feature of coldfusion? Dunno. But thanks for your help 🙂

Posts in this Series