Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
DAYohn #1
Setting a variable name with a variable in a loop
Here is the code that bombs: <cfloop index='x' from='1' to='10' step='1'>
<cfif #evaluate('form.totalhours#x#')# eq 'r'> <cfset total_hours_#x# =
#evaluate('form.remaining_#x#')#> <cfelse> <cfset total_hours_#x# =
#evaluate('form.totalhours#x#')#> </cfif> </cfloop> I want to loop through
and create up to 10 variables named total_hours_1 through total_hours_10. Then
assign a value to them. The assigning of the value works, but the creating the
variable names does not work. How do I work around this? (Of note, the
variable name is used as the value of a db insert.)
DAYohn Guest
-
Creating variable using loop
Ok the first part of my code has a loop that loops 1-5 then i want it to set session variables but i don't know how to go about doing this.. i want... -
Using Loop Index in variable
#form.rate#store## will throw an error as the sql query will get (assuming they selected 5):- 5store# Now as this is not surrounded by single... -
Newbie : Incrementing variable in a loop
Hi, I have a Mysql row with several similar fields such as PA1, PA2, PA3 ... I would like to be able to loop through these fiels using a... -
Setting "variable" global variable ?
Hi ! I wonder if there is any way in Ruby of setting a "variable" global variable at runtime, without using "eval". For example, could the... -
How to declare the result of a loop as a variable?
I'm trying to include a list of people that's the result of looping through a recordset in a CDONTS mail. I'm trying to Dim the output of a loop,... -
Kronin555 #2
Re: Setting a variable name with a variable in a loop
change <cfset total_hours_#x# = #evaluate("form.remaining_#x#")#> to:
<cfset foo = evaluate("total_hours_#x# = form.remaining_#x#")>
The foo is useless, your variable "total_hours_#x#" will be setup.
Kronin555 Guest
-
Ian O'Betz #3
Re: Setting a variable name with a variable in a loop
First off, you don't need most of those pound signs. Step="1" is default in
cfloop, so don't really need that either.
<cfloop index='x' from='1' to='10'>
<cfset SetVariable("total_hours_" & x, IIf(Evaluate("form.totalhours" & x)
EQ "r",'Evaluate("form.remaining_" & x)','Evaluate("form.totalhours_" &
x)'))>
</cfloop>
SetVariable() is what you are looking for. And I used an Immediate If
statement instead of the cfif/cfelse tags.
--
Ian O'Betz
Clear Results
[url]www.clearresults.net[/url]
"DAYohn" <webforumsuser@macromedia.com> wrote in message
news:d17jbe$htd$1@forums.macromedia.com...through> Here is the code that bombs: <cfloop index='x' from='1' to='10' step='1'>
> <cfif #evaluate('form.totalhours#x#')# eq 'r'> <cfset total_hours_#x# =
> #evaluate('form.remaining_#x#')#> <cfelse> <cfset total_hours_#x# =
> #evaluate('form.totalhours#x#')#> </cfif> </cfloop> I want to loopThen> and create up to 10 variables named total_hours_1 through total_hours_10.creating the> assign a value to them. The assigning of the value works, but the> variable names does not work. How do I work around this? (Of note, the
> variable name is used as the value of a db insert.)
>
Ian O'Betz Guest
-
eastinq #4
Re: Setting a variable name with a variable in a loop
You can also do it this way without using Evaluate(). There is more overhead
in using evaluate.
<cfloop index="x" from="1" to="10">
<cfif "form.totalhours#x#" eq "r">
<cfset "total_hours_#x#" = form["remaining_#x#"]>
<cfelse>
<cfset "total_hours_#x#" = form["totalhours#x#"]>
</cfif>
</cfloop>
eastinq Guest
-
DAYohn #5
Re: Setting a variable name with a variable in a loop
I discovered this works... <cfloop index='x' from='1' to='10' step='1'>
<cfif #evaluate('form.totalhours#x#')# eq 'r'> <cfif
#evaluate('form.remaining_#x#')# eq ''> <cfparam name='total_hours_#x#'
default='#evaluate('form.remaining_#x#')#'> <cfelse> <cfparam
name='total_hours_#x#' default='#evaluate('form.totalhours#x#')#'>
</cfif> </cfloop> Thanks for all of the input. Alex
DAYohn Guest



Reply With Quote

