Solved

loop problem.

Posted on 2003-11-20
7
286 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 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

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…
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 …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

617 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