I'm very curious why this is happening. I've run into it twice now, and after a ton of googling/so'ing, I haven't found any reason I actually understand. The gist of it:
Query 1: selectContent (6 records; no blanks/nulls etc)
Query 2: selectPricing (5 records; no blanks/nulls etc)
Output:
<cfloop query="selectContent">
<section>
#selectContent.h2#
<cfif selectContent.id eq 3>
<cfloop query="selectPricing" group="groupCol">
<table class="pricing">
<thead>
<tr>
<th>#description#</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<cfloop>
<tr>
<td>#selectPricing.description#</td>
<td>#selectPricing.price#</td>
</tr>
</cfloop>
</tbody>
</table>
</cfloop>
</cfif>
#selectContent.content#
</section>
</cfloop>
This will give the following error: Array index out of range: 5
The error only occurs when the second query has less records than the first. Essentially it feels like that first cfloop takes over the loop iteration from that second one and this causes the issue, but also only if you have that third grouped cfloop in there. The entire inner cfloop runs, as is there in the source.
I've come up with two ways to resolve this:
- do this with cfoutput/group, but that's relatively ugly as it means lots of closing of cfoutputs from other parts of the page.
- stick a cfbreak on that third cfloop if the currentRow matches the recordcount.
So, two questions:
Why is this even happening?
Should I be using a totally different approach here (the fact that googling/so'ing isn't finding others with this issue certainly seems to imply that...)?
EDIT I've filed this as a Coldfusion bug based on Adam Cameron's feedback below. Bug #3820049