Skip to main content
October 30, 2009
Answered

Need information on cfoutput tag inside of cfoutput tag

  • October 30, 2009
  • 1 reply
  • 614 views

Hey everyone,

Its been several years since I have been in CF land, but after 4+ years I'm back in the mix.

I need some help understanding what a snippet of code is doing.

The code is a cfoutput of a query that contains a nested cfoutput tag.

Why is there a nested cfoutput tag inside of the cfoutput for the query?

    This topic has been closed for replies.
    Correct answer ilssac

    Asuming the most common reason, since you did not show the code, is to group output on one or more fields.

    <cfoutput query="myQry" group="aColumn">

         Stuff to output once pre value of aColumn

         <cfoutput group="bColumn"

              Stuff to output once pre value of bColumn per value of aColumn

              <cfoutput>

                   Stuff to output for each record in the record set

              </cfoutput>

              Stuff to output once per value of bColumn per value of aColumn

         </cfoutput>

         Stuff to output once per value of aColumn

    </cfoutput>

    1 reply

    ilssac
    ilssacCorrect answer
    Inspiring
    October 30, 2009

    Asuming the most common reason, since you did not show the code, is to group output on one or more fields.

    <cfoutput query="myQry" group="aColumn">

         Stuff to output once pre value of aColumn

         <cfoutput group="bColumn"

              Stuff to output once pre value of bColumn per value of aColumn

              <cfoutput>

                   Stuff to output for each record in the record set

              </cfoutput>

              Stuff to output once per value of bColumn per value of aColumn

         </cfoutput>

         Stuff to output once per value of aColumn

    </cfoutput>

    October 30, 2009

    Thank you for your response, just to clarify for me regarding your 3rd cfoutput tag. Thats the one that is unclear to me.

    <cfoutput query="myQry" group="aColumn">
         Stuff to output once pre value of aColumn
         <cfoutput group="bColumn"
              Stuff to output once pre value of bColumn per value of aColumn
              <cfoutput>
                   Stuff to output for each record in the record set
                   Would this be multiple outputs? Such as if you were outputing products such as
                   aColum = Lets say Category Store
                   bColum = Lets say Category produce
                   the 3rd cfoutpu would spew out all records for types of produce
              </cfoutput>
              Stuff to output once per value of bColumn per value of aColumn
         </cfoutput>
         Stuff to output once per value of aColumn
    </cfoutput>

    So output could be something like

    Wal-Mart

         Produce

              Carrots

              Lettuce

              Tomatos etc.

    Shop-Right

         Produce

              Watermelon

              Grapes

              Lettuce etc.

    ilssac
    Inspiring
    October 30, 2009

    Asuming a record set that looks something like this from your query, then yes that is the kind of output you would generate.

    StoreSection
    Item
    Wal-MartProduceCarrots
    Wal-MartProduceLettuce
    Wal-MartProduceTomatos
    Shop-RightProduceWatermelon
    Shop-RightProduceGrapes
    Shop-RightProduceLettuce

    Then if you have a more complex record set that has multiple sections for each store, then your items would be grouped by each section under each store.

    StoreSection
    Item
    Wal-MartProduceCarrots
    Wal-MartProduceLettuce
    Wal-MartDryGoodsBlack Beans
    Wal-MarktDryGoodsRice
    Shop-RightProduceWatermelon
    Shop-RightProduceGrapes
    Shop-RightCannedGoodsTomato Soup
    Shop-RightCannedGoodsBlack Beans

    This would produce output that could look something like this:

    Wal-Mart

         Produce

              Carrots

              Lettuce

         DryGoods

              Black Beans

              Rice

    Shop-Right

         Produce

              Watermelon

              Grapes

         CannedGoods

              Tomato Soup

              Black Beans