CFOUTPUT and Array result sets

Imagine you have a query that returns a few results like Product Categories sold for a given period. You might have a query like:
<cfquery name="myQ" datasource="myDSN">
select distinct category from sales order by category.
</cfquery>
Your results might look something like this array:
["Games", "Movies", "Software" ]

We typically use cfoutput to dump the array into a table or onto the screen. But depending on where you put the query “name” yields different results.
<cfoutput>#myQ.category#</cfoutput>
yields only the first item in the array "Games"

vs
<cfoutput query="myQ">#category#</cfoutput>
yields all items in the array.

Both are valid answers. If you wanted to use logic with the first item in the array you could check the array value in the first position:
<cfif #myQ.category[1]# NEQ "Games">...No Games Sold... </cfif>

Cup size   
Select size then click on coffee cup.
This entry was posted in Code, Coldfusion. Bookmark the permalink.