Coldfusion - variable field name when looping through database query results

Posted by shifuimam on Stack Overflow See other posts from Stack Overflow or by shifuimam
Published on 2009-06-30T15:23:40Z Indexed on 2010/03/08 13:36 UTC
Read the original article Hit count: 516

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about coldfusion

Related posts about sql