Notice: With the launch of Adobe Cookbooks, this site will no longer be accepting new entries or posting new content. Thanks to everyone who submitted content!

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 at 6:48:39 AM EST.

CFML Referenced

<cfoutput>

Categories

Queries

Comments

Comment made by Michael White on May 21, 2006 at 8:09 PM
You saved my bacon. Didn't even know what this entry was for until I needed it.