Displaying a query in an HTML table using the CFTABLE tag in ColdFusion

Readability

Displaying a query in an HTML table using the CFTABLE tag in ColdFusion

The fol­low­ing exam­ple shows how you can quickly dis­play a data­base query in an HTML table using the <CFTABLE> tag in Cold­Fu­sion and spec­i­fy­ing the htmlTable attribute.


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



    
    
    

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

Row: Name: Price:
1 Enchanted Tree $350,000.00 USD
2 Par­adise $300,000.00 USD
3 Things $300,000.00 USD
4 Mys­tery $250,000.00 USD
5 Ideas $250,000.00 USD

The following example shows how you can quickly display a database query in an HTML table using the <CFTABLE> tag in ColdFusion and specifying the htmlTable attribute.

<cfquery name="getArt" datasource="cfartgallery" maxRows="5">
    SELECT a.ARTID, a.ARTNAME, a.DESCRIPTION, a.ISSOLD, a.LARGEIMAGE, m.MEDIATYPE, a.PRICE
    FROM ART a, MEDIA m
    WHERE a.MEDIAID = m.MEDIAID
    ORDER BY a.PRICE DESC
</cfquery>
 
<cftable query="getArt" htmlTable="true" colHeaders="true">
    <cfcol header="Row:" text="<em>#getArt.currentRow#</em>" align="center" />
    <cfcol header="Name:" text="#getArt.ARTNAME#" />
    <cfcol header="Price:" text="#dollarFormat(getArt.PRICE)# USD" />
</cftable>

The preceding code produces the following output:

Row: Name: Price:
1 Enchanted Tree $350,000.00 USD
2 Paradise $300,000.00 USD
3 Things $300,000.00 USD
4 Mystery $250,000.00 USD
5 Ideas $250,000.00 USD

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>