Why use eval at all?

<cfloop from="1" to="20" index="i">
  <cfif structKeyExists(form, 'post#i#_data')>
    <cfset variables['column_#i#']  = form['post#i#_data']>
  </cfif>
</cfloop>



-----Original Message-----
From: Dave Watts [mailto:[email protected]] 
Sent: October-13-10 1:28 PM
To: cf-talk
Subject: Re: Gone Brain dead


> I must have gone brain dead. Seem to me like I should be able to set field
> names with a value but it's not working. Know I've done something like
this
> before (this is just a sample of function... not the code):
>
> <cfloop from="1" to="20" index="i">
>        <cfoutput>
>        <cfset column_#i#="#evaluate("post#i#_data")#">
>        </cfoutput>
> </cfloop>
>
> I should get 20 fields, column_1 through column_20 but it's not liking the
> #i# being used to build the column_X fields.
>
> What am I doing wrong?

Any time you have nested hash marks, that's a good sign things aren't
right. Replace

<cfset column_#i#="#evaluate("post#i#_data")#">

with

<cfset "column_#i#" = evaluate("post" & i & "_data")>

or

<cfset Variables["column_#i#"] = evaluate("post" & i & "_data")>

or

<cfset Variables["column_" & i] = evaluate("post" & i & "_data")>

Or consider using an array for your column values.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
http://training.figleaf.com/

Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on
GSA Schedule, and provides the highest caliber vendor-authorized
instruction at our training centers, online



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:338157
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to