Skip to main content
Participant
August 10, 2008
Question

Using Dynamically-Generated Variables

  • August 10, 2008
  • 2 replies
  • 331 views
I'm sure there's a CF function to do this, I'm just not familiar with it.

I've got a simple query named "people" that returns three names, say: "Amber, Bob, Chuck." Now, I want to generate variables with the name: xStreetName where 'x' would be replaced. I'm using a CFLOOP, so 'x' would actually be something like #people.name#. So, I'd be left with three variables named AmberStreetName, BobStreetName, and ChuckStreetName.

The dynamically generated variables then populate a blank form. The user will then submit the Street Name values for Amber, Bob and Chuck.

On the next page, I'd like to use a dynamically-generated SQL statement to add both the dynamically-generated variable name and the associated values to a database.
    This topic has been closed for replies.

    2 replies

    Inspiring
    August 21, 2008
    <!--- ============================================================== --->
    <cffunction name="field_set" output="No">
    <cfargument name="field" type="string" default="">
    <cfargument name="value" type="string" default="">

    <cfset "#field#"= value>
    </cffunction>
    <!--- ============================================================== --->
    <cffunction name="field_get" output="No">
    <cfargument name="field" type="string" default="">
    <cfif isdefined("#field#") IS TRUE>
    <cfreturn evaluate("#field#")>
    </cfif>
    </cffunction>
    Inspiring
    August 10, 2008
    variables[variablepart & "contstantpart"]

    Storing the variable name seems like a bad idea.