/ Published in: ColdFusion
Create dynamic variables from a query or a list.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<cfquery name="settingsParameters" datasource="#dsn#"> SELECT NAME, VALUE FROM MY_SETTINGS WHERE ACTIVE = 1 AND SECTION = 'whatsNew' </cfquery> <!--- To output the results use one of these 2 mothods. The latter is the newer, simpler way to write it ---> <cfloop query="settingsParameters"> <cfset temp2 = SetVariable("settings.#settingsParameters.name#", settingsParameters.value) /> </cfloop> <!--- OR, CF >= 8 (i think) ---> <cfloop query="settingsParameters"> <cfset "settings.#settingsParameters.name#" = settingsParameters.value > </cfloop> <cfset myList = "something=blah;what=now;who=jim"> <!--- Loop over list breaking it up on semicolon. create a temp array and use array[1] for the name of the variable and array[2] as the value i.e. bupid=7; creates <cfset additionalParams.bupid = 7> ---> <cfloop list="#myList#" delimiters=";" index="i"> <cfset k = listToArray(i,"=")> <cfset "additionalParams.#k[1]#" = k[2] \> </cfloop>