• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

<cfoutput> problem in <cfloop>

I have a code below. Just a preview of my problem

<!---
If i have a variable value for exmple for accntNo1 to accntNo10 base after form submission
--->

accntNo1 = 'hello'
 accntNo2 = 'hello2'
....
accntNo10 = 'hello10'

<!---
Then i loop the idx from 1 to max or in this example 10
--->

<cfloop index="idx" from="1" to="max">            
            
<!---
 tmp_var will generate accntNo1  based on first loop      
 so...
 tmp_var = accntNo1
--->

<cfset tmp_var = 'accntNo#no#'>


<cfif IsDefined('tmp_var')>
  <cfset tmp_dval = #tmp_var#>
<cfelse>
  <cfset tmp_dval = "">
</cfif>       

</cfloop>

<!---
Then I just want that the   tmp_dval must equal to accntNo1
w/c is 'hello' declared above for example.

But the  tmp_dval resulted into 'accntNo1'
Hope someone can help
--->
0
mon_pacey8
Asked:
mon_pacey8
1 Solution
 
tim_csCommented:
Try this <cfset tmp_var = Evaluate("accntNo#no#")>

0
 
mkishlineCommented:
Evaluate would work, but there are some concerns about how slow it is. Slightly better would be:

<cfloop index="idx" from="1" to="#max#">
  <cfset tmp_dval = variables['accntNo' & idx] /> <!--- This will set tmp_dval to 'hello' for the first element, 'hello2' for the second, and so on --->
  <!--- Any other processing --->
</cfloop>
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now