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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cfloop not working with variables

Status
Not open for further replies.

evergrean100

Technical User
Joined
Dec 1, 2006
Messages
115
Location
US
I would like to put this in a loop but not sure how:

Code:
<cfoutput>
<cfset myavg1 = #myvar1# + 4>
avg1 = #myavg1#<br>
</cfoutput>

<cfoutput>
#NumberFormat(myvar1,"_.__")#
</cfoutput>
<br>
<cfoutput>
<cfset myavg2 = #myvar2# + 4>
avg2 = #myavg2#<br>

</cfoutput>

<cfoutput>

#NumberFormat(myvar2,"_.__")#

</cfoutput>


My attempt:
Code:
<cfloop index="i" list="1,2">

<cfoutput>
<cfset myavg#i# = myvar#i# + 4>
avg#i# = myavg#i#<br>
</cfoutput>

<cfoutput>
#NumberFormat(myvar#i#,"_.__")#
</cfoutput>
<br>
<cfoutput>
<cfset myavg#i# = myvar#i# + 4>
avg#i# = myavg#i#<br>

</cfoutput>

<cfoutput>

#NumberFormat(myvar#i#,"_.__")#

</cfoutput>
</cfloop>

It gives me error on my NumberFormat part where I try and put #'s inside #'s. Please advise how I can get this to work??
 
Try array notation. Also, you shouldn't have <cfoutput> tags inside a loop, and there's no reason to keep continuously opening and closing the <cfoutput> tags like in your examples, it's much more efficient to just open/close once.
Code:
<cfoutput>
	<cfloop index="i" list="1,2">	
		<cfset myavg[i] = myvar[i] + 4>
		<cfset myavg[i] = myvar[i] + 4>
		avg#i# = #myavg[i]#<br>	
		#NumberFormat(myvar[i],"_.__")#<br>	
		avg#i# = #myavg[i]#<br>
		#NumberFormat(myvar[i],"_.__")#
	</cfloop>
</cfoutput>

Hope This Helps!

ECAR
ECAR Technologies

"My work is a game, a very serious game." - M.C. Escher
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top