Coldfusion cfoutput grouping

The cfoutput tag has a group attribute that lets you group your data for reports. The outer most cfoutput must have the query name and the group but the inner groups can not have the query name. In the following query I have a table of categories, questions, and answers which need grouping for a report Answers are children Questions, Questions are children of Categories

For each category we will loop through the questions and for each question we will loop through all answers.


<cfquery name='q1' datasource='mydsn'>
select category_id, category,
question_id, question,
answer_id, answer
from mytable
group by category_id, category,
question_id, question,
answer_id, answer
</cfquery>
 
<cfoutput queryname='q1' group='category_id'>
Category: #category_id# - #category# <br />
<cfoutput group='question_id'>
Question: #question_id# - #question# <br />
<cfoutput group='answer_id'>
Answer: #answer_id# #answer# <br />
</cfoutput>
</cfoutput>
</cfoutput>

You can put the output into tables or nested lists. Changing the background color for each group also helps visually.

Cup size   
Select size then click on coffee cup.
This entry was posted in Code, Coldfusion, Snippets, SQL. Bookmark the permalink.