Nested Cfloop tags scope resolution

by @jehiah on 2004-04-28 13:52UTC
Filed under: All , ColdFusion

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

Example of Problem

<cfloop query="outerqueryset">   
    <cfloop query="innerqueryset">     
        <cfoutput>#outerqueryset.column1# #innerqueryset.column1#<br></cfoutput>
    </cfloop>
</cfloop>

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

Workaround

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

<cfloop query="outerqueryset">
    <cfloop query="innerqueryset">
        <cfoutput>#outerqueryset.column1[outerqueryset.currentrow]# #innerqueryset.column1#</cfoutput>
    </cfloop>
</cfloop>
Subscribe via RSS ı Email
© 2023 - Jehiah Czebotar