Specifying the number of records shown in a query using the CFDUMP tag in ColdFusion

Readability

Specifying the number of records shown in a query using the CFDUMP tag in ColdFusion

The fol­low­ing exam­ple shows how you can spec­ify the num­ber of records shown in a data­base query using the top attribute in the <CFDUMP> tag in ColdFusion.


    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
        AND a.ISSOLD = 0
    ORDER BY a.PRICE DESC



And the out­put of the <CFDUMP> tag is as fol­lows:
Setting the top attribute on the CFDUMP tag

As you can see from the pre­vi­ous screen­shot, the actual data­base query con­tains 24 rows, but the query result­set is fil­tered to only show the top 5 of 24 rows.

The following example shows how you can specify the number of records shown in a database query using the top attribute in the <CFDUMP> tag in ColdFusion.

<cfquery name="getArt" datasource="cfartgallery">
    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
        AND a.ISSOLD = 0
    ORDER BY a.PRICE DESC
</cfquery>
 
<cfdump var="#getArt#" top="5" />

And the output of the <CFDUMP> tag is as follows:
Setting the top attribute on the CFDUMP tag

As you can see from the previous screenshot, the actual database query contains 24 rows, but the query resultset is filtered to only show the top 5 of 24 rows.

Leave a Reply

Your email address will not be published.