Coldfusion - variable field name when looping through database query results
- by shifuimam
I have a set of column names in a table - e.g. foo1, foo2, foo3, foo4. I want to refer to these column names dynamically through a loop:
<cfloop index="i" from="1" to="4">
<cfset foo = Evaluate("query.foo" & i)>
</cfloop>
The above doesn't work - ColdFusion throws a "variable not defined" error, even though query.foo1 is a valid reference to the query results. How else can I do this?