Solved

loop problem.

Posted on 2003-11-20
7
278 Views
Last Modified: 2013-12-24
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.
0
Comment
Question by:spunog
  • 5
7 Comments
 
LVL 11

Accepted Solution

by:
hart earned 125 total points
ID: 9786869
the thing is ur logic is not proper.
because the i will keep on incrementing...

u will have to run a loop on the array length of question...

then inside the loop u will have to check wether
<cfoutput>
<cfloop from="1" to="arrayLen(question)" index="i">
<cfif questions[i].XmlAttributes["TYPE"] EQ 2>
<OPTION VALUE="#questions[i].XmlAttributes["CAPTION"]#">#questions   [i].XmlAttributes["CAPTION"]#
</cfif>
</cfloop>
</cfoutput>

let me know

Regards
Hart
0
 
LVL 11

Expert Comment

by:hart
ID: 9786877
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
0
 
LVL 11

Expert Comment

by:hart
ID: 9786878
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
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 35

Expert Comment

by:mrichmon
ID: 9788630
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.

0
 
LVL 9

Expert Comment

by:shooksm
ID: 9789821
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.
0
 
LVL 11

Expert Comment

by:hart
ID: 9794223
mrichmon, how is ur post different from mine????
have u given something that i haven't.

its just the duplicate....

Regards
Hart
0
 
LVL 11

Expert Comment

by:hart
ID: 9795792
thnkx for the A
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 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

13 Experts available now in Live!

Get 1:1 Help Now