How can I access a query column if I have the column name stored in a variable?

Use structure notation to access the recordset:

<cfset colName="lastname">
<cfoutput>
   #myQuery[colName][1]#
</cfoutput>

Keep in mind that with this notation you need to provide a row index as well, even within a query loop:

<cfset colName="lastname">
<cfoutput query="myQuery">
   #myQuery[colName][myQuery.currentrow]#<br />
</cfoutput>

This question was written by Christoph Schmitz
It was last updated on March 23, 2006.

Categories

Queries

Comments

comments powered by Disqus