Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

loop problem.

Posted on 2003-11-20
7
Medium Priority
?
289 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
7 Comments
 
LVL 11

Accepted Solution

by:
hart earned 500 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
How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

 
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

Turn your laptop into a mobile console!

The CV211 Laptop USB Console Adapter provides a direct Laptop-to-Computer connection for fast and easy remote desktop access with no software to install.

Question has a verified solution.

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

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

688 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