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].XmlAttribut es["TYPE"] # EQ 2">
<cfoutput>
<OPTION VALUE="#questions[i].XmlAt tributes[" CAPTION"]# ">#questio ns [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.
<cfloop CONDITION= "#questions[i].XmlAttribut
<cfoutput>
<OPTION VALUE="#questions[i].XmlAt
</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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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].XmlAttribut es["
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].XmlAt tributes[" CAPTION"]# ">#questio ns [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.
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].XmlAttribut
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
<OPTION VALUE="#questions[i].XmlAt
</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].Xml Attributes ["CAPTION" ]#">#aryCa ptions[i]. XmlAttribu tes["CAPTI ON"]#</OPT ION>
</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.
<cfset aryCaptions = XmlSearch(questions, "*/questions[@type=""2""]"
<SELECT>
<cfloop index="i" from="1" to="#ArrayLen(aryCaptions)
<cfoutput>
<OPTION VALUE="#aryCaptions[i].Xml
</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
have u given something that i haven't.
its just the duplicate....
Regards
Hart
thnkx for the A
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