Solved

loop problem.

Posted on 2003-11-20
7
281 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

778 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