House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

Dynamic Variable

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Torrent Girl
07/03/2012 01:58 PM

hi All. I have an application that creates an array based on a few variables. The application enters the contents of the array into a DB by looping over the array. My issue is that I need the array name in the loop to be dynamic based on another var I have set. EX: <cfset moduleGroup = "1A"> Here is how it goes: The arrays are set into session: <cfset session.ceuAppModules1A = [] />                          <cfloop query="course1Apply" startrow="1" endrow="6"> <cfset arrayAppend( session.ceuAppModules1A, "#INTMODULEID#" ) /> </cfloop> The 1A part of the array name is what can change. It can be 1B, 4A, etc. What I would like to do is when I enter the contents of the array into the DB, I'd like the name of the array loop to be dynamic: Here is my loop: <cfloop array="#session.ceuAppModules1A#" index="i"> I want the "1A" part of the array name to be dynamic but I have spent too much time trying to come up with the correct syntax. Any suggestions?

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Russ Michaels
07/03/2012 02:09 PM

I presume you have the dynamic part in another variable, in which case you could do this. <cfloop array="#evaluate("session.ceuAppModules#othervariable#")#" index="i"> ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Torrent Girl
07/03/2012 02:55 PM

----- Excess quoted text cut - see Original Post for more ----- I do. I'll try that. Thank you. But wait. won't this give me a value of '1A'?

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Russ Michaels
07/03/2012 04:24 PM

yes but presumably you are chagning that value, if not then you have nothing to work with. You need to be generating the dynamic name you plan to use somehow. ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Torrent Girl
09/12/2012 08:44 AM

>>I presume you have the dynamic part in another variable, in which case you > >I do. I'll try that. Thank you. > >But wait. won't this give me a value of '1A'? it's been a while since this post but thanks Russ that worked.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Leigh
07/03/2012 03:51 PM

>  the arrays are set into session: > <cfset session.ceuAppModules1A = [] />   To access the element dynamically, use structure notation, ie:          session["ceuAppModules"& theDynamicSuffixHere

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Leigh
07/03/2012 04:03 PM

>  the arrays are set into session: > <cfset session.ceuAppModules1A = [] />   > To access the element dynamically, use structure notation, ie:   >  session["ceuAppModules"& theDynamicSuffixHere   Obviously there should be a closing bracket "]". The response was cut off for some reason .... ------------------------- Leigh some extra text here just to see where the message is cut off .


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

May 20, 2013

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
       1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31   

Designer, Developer and mobile workflow conference