Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the nested cfoutput recordcount when using group

Consider the following:

<cfoutput query="resources" group="type">
    <h4>#type#</h4>
       <cfoutput>
          #name#
       </cfoutput>
 </cfoutput>

resources.recordcount would give me the total number of records, but is there an elegant way of finding out the recordcount of the nested data? e.g

<cfoutput query="resources" group="type">
    <h4>#type# (#noofrecords# of #resources.recordcount#)</h4>
       <cfoutput>
          #name#
       </cfoutput>
 </cfoutput>

I could probably do something hacky with loops, but wondered if there was a way of doing it using the cfoutput groups specifically.

like image 758
Neokoenig Avatar asked Dec 02 '22 18:12

Neokoenig


1 Answers

You could do an output before to get the count. This would be more efficient than doing a query of queries.

<cfoutput query="resources" group="type">
  <cfset noofrecords= 0>
  <cfoutput>
    <cfset noofrecords++>
  </cfoutput>
  <h4>#type# (#noofrecords# of #resources.recordcount#)</h4>
  <cfoutput>
    #name#
  </cfoutput>
</cfoutput>
like image 94
Matt Busche Avatar answered Feb 02 '23 01:02

Matt Busche