<cfoutput> problem  in <cfloop>

Posted on 2006-05-03
Last Modified: 2013-12-24
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      
 tmp_var = accntNo1

<cfset tmp_var = 'accntNo#no#'>

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


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
Question by:mon_pacey8
    LVL 15

    Expert Comment

    Try this <cfset tmp_var = Evaluate("accntNo#no#")>

    LVL 12

    Accepted Solution

    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 --->

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Suggested Solutions

    In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
    Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
    This video discusses moving either the default database or any database to a new volume.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now