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">

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 />

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




comments powered by Disqus