Skip to main content
September 14, 2008
Answered

Nested Query Loop

  • September 14, 2008
  • 2 replies
  • 794 views
I have a query that I want to loop over the data and display. The query is an inner join with one table being order numbers and the second being details on each order. They are joined by the order number. What i am trying to do is loop over the data and group all the details under the order number. I have tried numerous nesting configurations and I have had no luck. This is what I would like to see.

Order Number 1
Item 1
Item 2
Item 3

Order Number 2
Item 1
Item 2

Order Number 3
item 1
Item 2
Item 3
Item 4

Any recomendations?


    This topic has been closed for replies.
    Correct answer
    Thanks guys! I had been trying that approach but apparently I was doing something wrong before. I had been getting nesting cfoutput errors and then I was lost in a formatting mess. Thanks again for the direction.

    2 replies

    Inspiring
    September 14, 2008
    You could use the "group" attribute of cfoutput. In your sql query, sort the results by the [OrderNumber] column. Then group by [OrderNumber] in your output.

    <cfoutput query="yourQuery" group="OrderNumber">
    <!---- each order number will be displayed only once --->
    #OrderNumber#<br>

    <cfoutput>
    #ItemNumber#
    <cfoutput>
    </cfoutput>

    http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_m-o_16.html
    Correct answer
    September 14, 2008
    Thanks guys! I had been trying that approach but apparently I was doing something wrong before. I had been getting nesting cfoutput errors and then I was lost in a formatting mess. Thanks again for the direction.
    Inspiring
    September 14, 2008
    <cfoutput> tag has a GROUP attribute - check it out.
    the doc are available online if you do not have them.

    hth

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/