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

CFLOOP problem 1

Status
Not open for further replies.

cdw0308

Technical User
Oct 8, 2003
181
US
I am trying to output a set of variables from a dynamic table using a cfloop.

Here is my code.
Code:
<cfset j = 1>

<cfloop index = "RowCount" from = "1" to = #j#>
   <cfloop index="ColumnCount" from = "1" to = "3">
   		<cfoutput>txt[COLOR=red][b]#ColumnCount#[/b][/color]Row[COLOR=red][b]#RowCount#[/b][/color]</cfoutput>&nbsp;&nbsp;
	</cfloop><br><br>
   <cfset j = j + 1>
</cfloop>

I am trying to output a variable named #txt1Row1# , #txt1Row2#, #txt1Row3# and so on..
My problem is when I put pound signs around
Code:
<cfoutput>#txt[COLOR=red][b]#ColumnCount#[/b][/color]Row[COLOR=red][b]#RowCount#[/b][/color]#</cfoutput>
I get an error because it effect the pound signs already there in varialbes #RowCount# and #ColumnCount#

Any help is greatly appreciated.
 
try to reference your variables like so:
Code:
#VARIABLES["txt" & ColumnCount]#

=========================================
Don't sweat the petty things and don't pet the sweaty things.
 
I am getting the error
Element txt1Row1 is undefined in a Java object of type class coldfusion.runtime
txt1Row1 is a variable not an element so that may be one problem.
Here is what I have so far...
Code:
<cfset j = 1>

<cfloop index = "RowCount" from = "1" to = #j#>
   <cfloop index="ColumnCount" from = "1" to = "3">
   		<cfoutput>#VARIABLES["txt" & ColumnCount & "Row" & RowCount]#</cfoutput>&nbsp;&nbsp;
	</cfloop><br><br>
   <cfset j = j + 1>
</cfloop>

Any ideas on what needs changed??
 
I think what you are looking for is the Evaluate() function. Try, #Evaluate("txt" & ColumnCount & "Row" & RowCount)#.

John
 
jc, that is the same thing as what was posted above, except less efficient.

the variables scope is a structure (key,value) and can be accessed as such much nicer than evaluate.


CDW: copy / paste to see it work, there must just be a syntax error on your side somewhere. Make sure it's not trying to read vars that don't exist. check with structKeyExists to prevent an error.
Code:
<cfset test_1 = 1>
<cfset test_2 = 2>
<cfset test_3 = 3>

<cfoutput>
<cfloop from="1" to="3" index="i">

	test_#i# = #variables["test_" & i]#<br/>

</cfloop>
</cfoutput>

<cfdump var="#variables#">

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