With the public release of ColdFusion 10 Beta yesterday, I thought I’d play around a bit with some of the new capabilities. One of the features added in this release is the ability to group in query loops using <cfloop>.

As expected, this is pretty straightforward, and has the same capabilities as the <cfoutput> corollary. Here’s a quick example:

<cfquery name="qproducts" datasource="somedatasource">
     select *
     from   products
     order by category,subcategory,product
</cfquery>

<cfoutput>
     <cfloop query="qproducts" group="category">
          <h1>#category#</h1>
          <cfloop group="subcategory" groupcasesensitive="true" >
               <h2>#subcategory#</h2>
               <cfloop>
                    #product#<br />
              </cfloop>
          </cfloop>
     </cfloop>
</cfoutput>

Pretty simple, but something which I know a lot of people have wanted for quite a while. Well, now you have it!

Share this: