Skip to main content
Inspiring
April 7, 2008
Question

cfloop question/help

  • April 7, 2008
  • 1 reply
  • 425 views
I have the following cfloop in my action page. It is not working so I put in cfouput to see what values are returned.

<cfif isDefined("form.fieldnames") and mid(form.fieldnames,1,4) is "Del_">

<cfloop index="i" list="#form.fieldnames#" delimiters=",">
<cfoutput>loop is from i, list is #form.fieldnames#<br></cfoutput>
<cfif left(i,4) is "del_">
<cfset select_urdn_number = removechars(i,1,4)>
<cfset select_urdn_number = #evaluate(select_urdn_number)#>
<cfoutput>evaluate urdn nubmer is #select_urdn_number#<br></cfoutput>
</cfif>

Here is the output I am getting from the cfoutput :
loop is from i, list is DEL_2178,DEL_2921,REGION,SITE,ACTIVITY_TYPE
evaluate urdn nubmer is 2178
loop is from i, list is DEL_2178,DEL_2921,REGION,SITE,ACTIVITY_TYPE
evaluate urdn nubmer is 2921
loop is from i, list is DEL_2178,DEL_2921,REGION,SITE,ACTIVITY_TYPE
loop is from i, list is DEL_2178,DEL_2921,REGION,SITE,ACTIVITY_TYPE
loop is from i, list is DEL_2178,DEL_2921,REGION,SITE,ACTIVITY_TYPE


The evaluate urdn numbers are correct, I am suppose to get two records, but the last part repeats three times (why ?) and when I query again to display the records, it shows the first one, the the second four times :

URDN 2178 2178
URDN 2921 2921
URDN 2921 2921
URDN 2921 2921
URDN 2921 2921


Why is this happening and what do I need to do to only get the two records ?

Thanks
    This topic has been closed for replies.

    1 reply

    Inspiring
    April 7, 2008
    see how many fields you have in the form? see how many outputs you get?
    see the connection?

    your loop is wrong. you are looping over all fields in the form instead
    of only over the ones that hold the data you need.

    all your loop logic has to be within <cfif left(i,4) is "del_"></cfif>

    also, removechars(i,1,4) can be easily replaced with right(i, len(i)-4)
    or even better with listlast(i, "_")
    and there's no need to evaluate() anything, i believe...

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    Inspiring
    April 7, 2008
    quote:

    Originally posted by: Newsgroup User
    and there's no need to evaluate() anything, i believe...

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/


    Neither do I.