Displaying a query in an HTML table using the CFTABLE tag in ColdFusion
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.
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 preceding code produces the following output:
Row:
Name:
Price:
1
Enchanted Tree
$350,000.00USD
2
Paradise
$300,000.00USD
3
Things
$300,000.00USD
4
Mystery
$250,000.00USD
5
Ideas
$250,000.00USD
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.
<cfqueryname="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><cftablequery="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>
<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>