Displaying a grouped query using nested CFOUTPUT tags in ColdFusion

Readability

Displaying a grouped query using nested CFOUTPUT tags in ColdFusion

The fol­low­ing exam­ple shows how you can dis­play a grouped query result using nested <CFOUT­PUT> tags and set­ting the group attribute in ColdFusion.


    SELECT a.ARTID, a.ARTNAME, a.DESCRIPTION, a.ISSOLD, m.MEDIATYPE
    FROM ART a, MEDIA m
    WHERE a.MEDIAID = m.MEDIAID
    ORDER BY a.ISSOLD ASC, a.PRICE DESC



SOLD (#yesNoFormat(getArt.ISSOLD)#)

  • [#getArt.MEDIATYPE#] #getArt.ARTNAME# -- #getArt.DESCRIPTION#

The pre­ced­ing code pro­duces the fol­low­ing output:

SOLD (No)

  • [Paint­ing] Enchanted Tree — Pastels
  • [Paint­ing] Par­adise — Pastels
  • [Paint­ing] Mys­tery — Pastels
  • [Paint­ing] Morn­ing For­est — Oil
  • [Paint­ing] Melon — Pastels

SOLD (Yes)

  • [Paint­ing] Things — Oil
  • [Paint­ing] Ideas — Oil
  • [Paint­ing] Moun­tains — Pastels
  • [Paint­ing] Man on Stool — Oils
  • [Paint­ing] 1958 — Charcoal

The following example shows how you can display a grouped query result using nested <CFOUTPUT> tags and setting the group attribute in ColdFusion.

<cfquery name="getArt" datasource="cfartgallery">
    SELECT a.ARTID, a.ARTNAME, a.DESCRIPTION, a.ISSOLD, m.MEDIATYPE
    FROM ART a, MEDIA m
    WHERE a.MEDIAID = m.MEDIAID
    ORDER BY a.ISSOLD ASC, a.PRICE DESC
</cfquery>
 
<cfoutput query="getArt" group="ISSOLD">
<h2>SOLD (#yesNoFormat(getArt.ISSOLD)#)</h2>
<ul>
<cfoutput>
    <li>[#getArt.MEDIATYPE#] <em>#getArt.ARTNAME#</em> -- #getArt.DESCRIPTION#</li>
</cfoutput>
</ul>
</cfoutput>

The preceding code produces the following output:

SOLD (No)

  • [Painting] Enchanted Tree — Pastels
  • [Painting] Paradise — Pastels
  • [Painting] Mystery — Pastels
  • [Painting] Morning Forest — Oil
  • [Painting] Melon — Pastels

SOLD (Yes)

  • [Painting] Things — Oil
  • [Painting] Ideas — Oil
  • [Painting] Mountains — Pastels
  • [Painting] Man on Stool — Oils
  • [Painting] 1958 — Charcoal

Leave a Reply

Your email address will not be published.