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

Nested CFOUTPUT group processing...

Engaged ,
Dec 20, 2008 Dec 20, 2008

Copy link to clipboard

Copied

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.

Views

2.9K

Translate

Translate

Report

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 ,
Dec 20, 2008 Dec 20, 2008

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Engaged ,
Dec 21, 2008 Dec 21, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 ,
Dec 21, 2008 Dec 21, 2008

Copy link to clipboard

Copied

quote:

Originally posted by: Kapitaine
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?


First you say it's not possible, then you ask how it works. H'mmmm.

Votes

Translate

Translate

Report

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
Engaged ,
Dec 22, 2008 Dec 22, 2008

Copy link to clipboard

Copied

Sorry Dan. What I meant to say was that your solution of a UNION is a good idea for a typical situation like this. But in my CURRENT situation this is not possible. Hmm, nevermind! I'll keep pressing on.

Thanks for the info though.

Votes

Translate

Translate

Report

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
Guest
Dec 22, 2008 Dec 22, 2008

Copy link to clipboard

Copied

You could convert query bar to an array or structure or an array of structures (there is a UDF to do this at CFLib.org). Then use cfloop to iterate over it. You will likely need to write a bunch of code to receate the grouping effect but is \t should get you around the limitation of trying to nest different queries.

Votes

Translate

Translate

Report

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 ,
Dec 22, 2008 Dec 22, 2008

Copy link to clipboard

Copied

Kapitaine wrote:
> Sorry Dan. What I meant to say was that your solution of a UNION is a good idea
> for a typical situation like this. But in my CURRENT situation this is not
> possible. Hmm, nevermind! I'll keep pressing on.
>
> Thanks for the info though.
>

It is not too difficult to recreate the <cfoutput query="" group=""...>
grouping functionality with <cfloop query=""...>. You just have to
write the basic logic. All the group paramter does is take a section of
code an run it *if* the value in a given field changes from the previous
value.

Here is a 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#
</cfif>
<!--- output content here for every record.
#myQuery.bField#
</cfloop>
</cfoutput>

Not as clean and pretty as normal nested <cfoutput...> tags, but when
they don't work it is good to understand the underlining logic so that
you can modify it to get the job done.


Votes

Translate

Translate

Report

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 ,
Dec 22, 2008 Dec 22, 2008

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

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
Engaged ,
Dec 25, 2008 Dec 25, 2008

Copy link to clipboard

Copied

LATEST
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

Votes

Translate

Translate

Report

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 ,
Dec 21, 2008 Dec 21, 2008

Copy link to clipboard

Copied

Do a union query of queries with foo and bar. select contstants to match up the fields if necessary.

Votes

Translate

Translate

Report

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
Documentation