Link to home
Start Free TrialLog in
Avatar of spunog
spunog

asked on

loop problem.

When this loop reaches its last iteration, the condition is is coming back as undefined , which causes the page to not load properly :
<cfloop CONDITION= "#questions[i].XmlAttributes["TYPE"]# EQ 2">
  <cfoutput>
    <OPTION VALUE="#questions[i].XmlAttributes["CAPTION"]#">#questions   [i].XmlAttributes["CAPTION"]#
  </cfoutput>
<cfset i = i + 1>
</cfloop>

So how do I get this loop to work as I need the condition to be what it is in order for the loop to work effectively.
ASKER CERTIFIED SOLUTION
Avatar of hart
hart
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
change to="arrayLen(question)"
this to to="#arrayLen(question)#"

i hope this will work.. but the basic logic is to run a loop on he length of the questions..

hope u understand what i am trying to say

Regards
Hart
change to="arrayLen(question)"
this to to="#arrayLen(question)#"

i hope this will work.. but the basic logic is to run a loop on he length of the questions..

hope u understand what i am trying to say

Regards
Hart
Avatar of mrichmon
mrichmon

No I think what spunog is trying to do is to only run this loop when the question type is 2.

I am guessing that this is because questions of type 2 require selects as the form of answer.

I am thinking that it is possible that the double quotes are the problem since CF could be reading it as this :

CONDITION= "#questions[i].XmlAttributes["

Actually if I were you I would rewrite the code as one large loop over i and then use an if for this question like this :

<cfloop index="i" from="1" to="#ArrayLen(question)#">
<cfoutput>
<cfif questions[i].XmlAttributes["TYPE"] EQ 2>
<OPTION VALUE="#questions[i].XmlAttributes["CAPTION"]#">#questions   [i].XmlAttributes["CAPTION"]#
</cfif>
</cfoutput>
</cfloop>

But you could also try replacing the inner double quotes with single quotes and see if that works too.

Just use XPath to get only the elements you wish to use.  I am not a 100% sure on the structure of the XML doc you are using but you should be able to do something like the following:

<cfset aryCaptions = XmlSearch(questions, "*/questions[@type=""2""]")>
<SELECT>
<cfloop index="i" from="1" to="#ArrayLen(aryCaptions)#">
<cfoutput>
<OPTION VALUE="#aryCaptions[i].XmlAttributes["CAPTION"]#">#aryCaptions[i].XmlAttributes["CAPTION"]#</OPTION>
</cfoutput>
</cfloop>
</SELECT>

This will filter out any questions where the type attribute equals 2.  Again, depending on the structure of your XML doc, you may not need the */ at the beginning of the XPath query.
mrichmon, how is ur post different from mine????
have u given something that i haven't.

its just the duplicate....

Regards
Hart
thnkx for the A