Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Variable Names & Values

Status
Not open for further replies.

JohnandSwifty

Technical User
May 31, 2005
192
GB
I need to be able to transfer the values of dynamically named session variables to a local variable.

E.G.

I need to set a session variable (which works)

<cfset "Session.Q#URL.Number#.Number" = GetNumbers.Number>

And then do this...(which doesnt work)

<cfset Number= "Session.#URL.Number#.Number">
 
although its best to avoid evaluate whenever possible:

Code:
<cfset Number = #Evaluate('Session.#url.number#.Number')#>
 
Why not keep it in a familiar structure bracket notation format?

this should do the trick...
Code:
<!--- fake some values to set up --->
<cfset url.number = 3>
<cfset GetNumbers.Number = 4>

<!--- set the session variable as you mentioned it was done  except in what I would call a more  proper way 
yours : <cfset "Session.Q#URL.Number#.Number" = GetNumbers.Number> --->

<cfset Session["Q"&URL.Number].Number = GetNumbers.Number>

<!--- and set a local variable as you mentioned you needed --->
<cfset number = Session["Q"&URL.Number].number>

<!--- dump it all out to check it.. --->
<cfdump var="#variables#">

<cfdump var="#session#">

Kevin

Phase 1: Read the CFML Reference
Phase 2: ???
Phase 3: Profit!
 
what do you mean? - 'nevermind, I blew it on that one...???'

anyway thanks for your input - i have been trying the array/structure syntax but for some reason it only works 5 times out of ten?...

Ive ended up storing it all in a query and getting at the various different values with Q of Q.
 
Because I went back to play with it again the next day, and it errored. Don't know if it was a session timeout issue, or what. So does it really work? I dunno...

Kevin

Phase 1: Read the CFML Reference
Phase 2: ???
Phase 3: Profit!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top