Skip to main content
December 20, 2008
Question

Nested CFOUTPUT group processing...

  • December 20, 2008
  • 2 replies
  • 3301 views
Hi,

I have been using the group attribute of CFOUTPUT for some time now, it's really really helped a lot!

However, I am now in a situation where two separate queries (each of which needs it's own grouping) need to be nested. But, this doesn't seem to be possible because CF throws an error about the query "driving" the process.

See the example code below...

<cfoutput query="foo" group="a">
#foo.a#
<cfoutput query="foo" group="b">
#foo.b#
</cfoutput>

</cfoutput>

This works great, BUT, if I do the following it will fail.

<cfoutput query="foo" group="a">
#foo.a#
<cfoutput query="foo" group="b">
#foo.b#

<cfoutput query="bar" group="c">
#bar.c#
</cfoutput>

</cfoutput>

</cfoutput>


However, for many reasons I NEED to have nested grouping like this and I can't see another way around it. While it is perfectly fine to have queries looped within other queries (usually with CFLOOP) CFLOOP does not support the GROUP attribute like CFOUTPUT does.

If anyone can help I'd really appreciate it. I'm not sure how to get around this issue at all.

Thanks,
Mikey.
    This topic has been closed for replies.

    2 replies

    Inspiring
    December 21, 2008
    Do a union query of queries with foo and bar. select contstants to match up the fields if necessary.
    Inspiring
    December 20, 2008
    I would look for a way to build up a list from each cfoutput separately
    (i.e not nested, using group however you like and 'listAppend()' or
    'valueList()' to build the lists), and then use nested <cfloop
    list="listName" etc> to create the desired output.


    Michael Evangelista, Evangelista Design
    Web : www.mredesign.com Blog : www.miuaiga.com
    Developer Newsgroups: news://forums.mredesign.com
    December 21, 2008
    Hi Dan, that UNION sounds like a good idea for a situation like this, but in my particular instance it's just not possible. I'm curious though, how would grouping work with a UNION query? Is it any different?

    Do you think an issue like this could be resolved if the CFLOOP tag support the GROUP attribute? I think so. Because we can still do inner queries with CFLOOP...and In my case this works. But I just need the grouping you see. So the problem is not so much the nested queries, but more the nested CFOUTPUTS of different queries.

    Thanks.
    Mikey.
    December 26, 2008
    Ian Skinner wrote:

    Here is a super simple correction to my original ...

    > super simple sample.
    >
    > <cfoutput>
    > <cfset aFieldValue = "">
    > <cfloop query="myQuery">
    > <cfif myQuery.aField NEQ aFieldValue>
    > <!--- output grouped content here, once per value of aField. --->
    > #myQuery.aField#
    <cfset aFieldValue = myQuery.aField> <!--- new line --->
    > </cfif>
    > <!--- output content here for every record.
    > #myQuery.bField#
    > </cfloop>
    > </cfoutput>

    quote:

    Originally posted by: Newsgroup User
    Ian Skinner wrote:

    Here is a super simple correction to my original ...

    > super simple sample.
    >
    > <cfoutput>
    > <cfset aFieldValue = "">
    > <cfloop query="myQuery">
    > <cfif myQuery.aField NEQ aFieldValue>
    > <!--- output grouped content here, once per value of aField. --->
    > #myQuery.aField#
    <cfset aFieldValue = myQuery.aField> <!--- new line --->
    > </cfif>
    > <!--- output content here for every record.
    > #myQuery.bField#
    > </cfloop>
    > </cfoutput>



    Thank you thank you thank you for this Ian. I tried your method and it worked a treat. So much simpler than I thought it would be and I have no problems with it. Much appreciated.

    Thank you also to everyone else who chipped in their ideas.

    Thanks!!
    Mikey