In a previous example, “Querying a database in ColdFusion using the CFQUERY tag”, we saw how you could query a database in ColdFusion 9 using the <CFQUERY> tag.
The following example shows how you can get the number of records returned by a database query in ColdFusion by using the
recordCount property on the query object.
<cfquery name="getArt" datasource="cfartgallery"> SELECT * FROM ART </cfquery> <cfoutput>#getArt.recordCount# records found</cfoutput>
The preceding code produces the following output:
55 records found
If you only want the number of items in a query, you could also use the SQL COUNT() method, as seen in the following example:
<cfquery name="getArt" datasource="cfartgallery"> SELECT COUNT(*) AS numItems FROM ART </cfquery> <cfoutput>#getArt.numItems# records found</cfoutput>