How to get a dynamic attribute name in cfloop over query in ColdFusion
- by Kip
I'm inside a cfloop over a query. I want to get an attribute, but I won't know what that attribute will be until runtime. Using #qryResult[MyAttr]# fails with the error "Complex object types cannot be converted to simple values." What is the syntax for doing this?
Here is a simplified example:
<cfquery datasource="TestSource" name="qryResult">
SELECT * FROM MyTable
</cfquery>
<cfloop query="qryResult">
<cfset MyAttr="autoid" />
<cfoutput>
Test 1: #qryResult.autoid# <br/> <!--- succeeds --->
Test 2: #qryResult[MyAttr]# <br/> <!--- fails --->
</cfoutput>
</cfloop>