How to set a dynamic variable name?
<cfloop from="1" to="10" index="i">
<cfset "request.var_#i#" = i>
</cfloop>
<cfdump var="#request#">
11170 viewed | 4 opinion(s) | del.icio.us | Digg it | Tjarko @ 13/11/02 0:00 cet


All files are strictly confidential: all information is classified.
© Copyright 2002 - 2013 mximize.com.
All right reserved.
<cfloop from="1" to="10" index="i">
<cfset "request.var_#i#" = i>
</cfloop>
<cfdump var="#request#">
11170 viewed | 4 opinion(s) | del.icio.us | Digg it | Tjarko @ 13/11/02 0:00 cet
Thanks a bunch! I've been wrestling with this for the last ~30 minutes, and a little pair of quotes was all I was missing... :-)
Take care,
- Eran
21 October 2007 6:25 cet
To create a dynamic variable name you need to use evaluate().This function lets you concatenate variables and/or strings to create a variable name and then evaluates that variable to its value.
12 November 2007 19:11 cet
I'm sorry Maija, but you should never ever user evaluate() It's a total overload for coldfusion. The best way is the way described above, this has no impact on performance and the evaluate() function is really bad for performance. Please don't ever use this function again, or be very very sure that you absolutly have to.
12 November 2007 20:02 cet
simple quotes, I'm amazed.CF continues to amaze me with its power.Thank you for posting this.Your solution was the first link in Google with the following: coldfusion set variable in a variable name
16 May 2008 16:49 cet