[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

cfloop. cfbreak

Posted on 2008-02-05
2
Medium Priority
?
678 Views
Last Modified: 2012-06-27
Experts,

I have this code below that doesn't seem to be working correctly.  This data is getting spit out into a table, and whenever I have students that did not answer any questions, I am expecting a '0', but instead getting a blank row.  If a student looks at a question, but doesn't answer we send this string to the database "noag^tasktime~2.00"  What I think is happening is when the <cfset matchFound = 1> it does break the loop because it is simply looking to see if something is in the database for this student.  I didn't write this code, and I'm not sure how to get around this.  If anyone has any suggestions, it would be greatly appreciated.  

The code.....
<cfoutput query="getstudent">
    <cfset s = s +1>
    <tr>
      <th align="left" scope="row" style="white-space:nowrap; ">#getstudent.lastName#, #getstudent.firstName#</th>
      <td align="right">#NumberFormat(studentCorrectPercentage[s], '99')#%</td>
      <cfloop index="j" list="#gettestlet.includedItems#" delimiters=",">
        <!--- this loop compare the items answered with the whole list items, if there is no answer, fill 0, otherwise indicate correct or not --->
        <cfloop index="k" from="1" to="#ArrayLen(itemsAnsweredForEachStudent[s])#">
          <cfif itemsAnsweredForEachStudent[s][k] eq j>
            <td align="center" class="item_mark"><cfif studentPerformanceOnEachItem[s][k] eq 1>
                C
                <cfelse>
                X
              </cfif>
              <!---cfoutput>#studentPerformanceOnEachItem[s][k]#</cfoutput--->
            </td>
            <cfset matchFound = 1>
            <cfbreak>
            <cfelse>
            <cfset matchFound = 0>
          </cfif>
        </cfloop>
        <cfif matchFound eq 0>
          <td align="center" class="item_mark"> O </td>
        </cfif>
      </cfloop>
    </tr>
  </cfoutput>
0
Comment
Question by:nmarano
2 Comments
 
LVL 39

Accepted Solution

by:
gdemaria earned 2000 total points
ID: 20829457
Not sure if this will do it, but if the array length of itemsAnsweredForEachStudent
in this line:
<cfloop index="k" from="1" to="#ArrayLen(itemsAnsweredForEachStudent[s])#">
is zero (there are no answers?)  then you will not process any of the code below it.

I suggest moving the matchFound = 0 before the loop instead of in the CFELSE statement so you can handle any time the arrayLen is 0.

See the attached code..
<cfoutput query="getstudent">
    <cfset s = s +1>
    <tr>
      <th align="left" scope="row" style="white-space:nowrap; ">#getstudent.lastName#, #getstudent.firstName#</th>
      <td align="right">#NumberFormat(studentCorrectPercentage[s], '99')#%</td>
      <cfloop index="j" list="#gettestlet.includedItems#" delimiters=",">
        <cfset matchFound = 0> <!--- assume no match, in case array len is 0 --->
        <cfloop index="k" from="1" to="#ArrayLen(itemsAnsweredForEachStudent[s])#">
          <cfif itemsAnsweredForEachStudent[s][k] eq j>
            <td align="center" class="item_mark">
			  <cfif studentPerformanceOnEachItem[s][k] eq 1>
                C
              <cfelse>
                X
              </cfif>
            </td>
            <cfset matchFound = 1>
            <cfbreak>
          </cfif>
        </cfloop>
        <cfif matchFound eq 0>
          <td align="center" class="item_mark"> O </td>
        </cfif>
      </cfloop>
    </tr>
  </cfoutput>

Open in new window

0
 
LVL 2

Author Closing Comment

by:nmarano
ID: 31428275
Maria-
As always, thanks for the help.  Very much appreciated
-Nick
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Question has a verified solution.

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

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.

590 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