Copy link to clipboard
Copied
I have a query that returns 31 results. The db is set up with a file name, url, membership, submembership. I want to create a bulleted list from the 31 records in the following manner
1
2
3
4
The question is ... the best way to do this. Is it easier to loop through the query and crete an array for each item? Thanks.
Copy link to clipboard
Copied
The group attribute of cfoutput should work.
Copy link to clipboard
Copied
I dont see how that would work right. If i use
<cfoutput query="healthyliving" group="membership">
<li>#title#</li>
</cfoutput>
I only get like 3 items.
membership is, in the example, 1, 2, or 3 etc. The submembership is the subitem1 etc. I dont see how the grouping would work right. Do you have a code example?
Copy link to clipboard
Copied
There is a code example in the documentation, but it does not mention that you can have nested grouping. Something like this:
<cfoutput query="xxx" group="field1">
#data grouped at this level#
<cfoutput group="field2">
#data grouped at this level#
<cfoutupt>
#ungrouped data#
closing tags.
Make sure your query has an order by clause that coincides with the way you want to group your output. For my example, it would be:
select etc
order by field1, field2
Copy link to clipboard
Copied
Just to clarify on something - using the group attribute will loop once for each unique value of that field (assuming your data is ordered by that field). using a second <cfoutput> block INSIDE of the <cfoutput group=""> tags will cause CF to loop over each record inside of that subgroup:
<cfoutput query="healthyliving" group="membership">
#membership#
<ul>
<cfoutput>
<li>#title#</li>
</cfoutput>
</ul>
</cfoutput>
Should get you where you need to go. As Dan mentioned you can use nested groupings, but for your example the above syntax should be sufficient.
Hope that helps,
- Michael
*Updated - added your variables to the example