Hey everyone! Today, I realized that I've encount...
# cfml-general
s
Hey everyone! Today, I realized that I've encountered an issue with cfoutput that I hadn't noticed before!
<cfoutput query="myquery">
#myquery.name#<br>
</cfoutput>
This will produce output like this,
Copy code
name1
name2
name3
But I've mistakenly put an additional cfoutput inside the loop.
<cfoutput query="myquery">
<cfoutput>#myquery.name#</cfoutput><br>
</cfoutput>
I got this output with the inner cfoutput tag,
Copy code
name1
name2
name3
name2
name3
name3
(that was just a sample qry, I had lot of additional index loops inside my cfoutput queries) I spent almost an hour debugging this issue in my app 🥲 Its in both CF and Lucee. It would be great if anyone explain this? I suspect its due to nested cfoutputs, Any thoughts on this?
r
It's doing implicit grouping because of the nested cfoutputs with a query. Lookup using the group attribute with cfoutput. https://cfdocs.org/cfoutput
s
But without group attribute, it should just print the query's column values right? cfoutput acting as a grouping here?
Correct me if I am wrong.
r
The cfoutput inside a cfoutput with a query will automatically group. So your code was getting converted to the following.
Copy code
<cfoutput query="myquery" group="name">
    <cfoutput>#myquery.name#</cfoutput><br>
</cfoutput>
👍 1
👍🏻 1
s
Oh ok thanks @Rodney :). I am unaware of that one.