How to get a dynamic attribute name in cfloop over query in ColdFusion
Posted
by Kip
on Stack Overflow
See other posts from Stack Overflow
or by Kip
Published on 2010-04-05T21:48:16Z
Indexed on
2010/04/05
21:53 UTC
Read the original article
Hit count: 196
coldfusion
|query
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>
© Stack Overflow or respective owner