Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Query to bulleted list

Community Beginner ,
Nov 11, 2011 Nov 11, 2011

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

  • item1
  • item2

2

  • item1
  • item2

3

  • item1
  • item2
    • subitem1
    • subitem2

4

  • item1
  • item2

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.

889
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 11, 2011 Nov 11, 2011

The group attribute of cfoutput should work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 11, 2011 Nov 11, 2011

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 11, 2011 Nov 11, 2011

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 14, 2011 Nov 14, 2011
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources