Looping in this case should be pretty easy. Since you are going to have
multiple form elements by the name "grade" the form is going to submit
them all together as a comma separated list. The easiest way to handle
it is this:

<cfloop index="UU" list="#form.grade#" delimiters=",">
        <!--- PROCESS EACH UU VALUE HERE --->


</cfloop> 

Inside the loop each list item will be represented by the variable "UU"
(in this case, you can set it to whatever you want). So if you list is
389-A,385-B,388-A then it will loop three times, and on the first loop
UU will equal 389-A and the second time UU will equal 385-B and on the
third time UU will equal 388-A.

Hope this helps,
Mike

-----Original Message-----
From: Gary Strommen [mailto:[EMAIL PROTECTED] 
Sent: Monday, June 18, 2007 3:54 PM
To: CF-Newbie
Subject: Array or CFScript?

I am creating a form where the user (a teacher) can submit all of his
students grades in one shot.  After the user identifies himself and his
class (as there are multiple ones of each), his students come up with a
pull down menu on the side of each student's name with the choices of
"A", "B", "C", "D", or "F".  As the students records are being pulled
through a query, I am trying to identify each record by it's primary
key.  Here is the code I am using for this page:

<cfoutput query="qGetStudents">
   #qGetStudents.fName# 
      <cfif qGetStudents.MI IS NOT "">
         #qGetStudents.MI#
      </cfif> #qGetStudents.lName# -
   <select name="grade" size="1" >
      <option value="" selected="selected"></option>
      <option value="#qGetStudents.primaryKey#-A">A</option>
      <option value="#qGetStudents.primaryKey#-B">B</option>
      <option value="#qGetStudents.primaryKey#-C">C</option>
      <option value="#qGetStudents.primaryKey#-D">D</option>
      <option value="#qGetStudents.primaryKey#-F">F</option>
   </select><br />
</cfoutput>             

I am not sure if trying to create an array here would be a better
option.  I am not familiar with them at this point.  I have opted to try
and use a "DO / WHILE" loop instead although I am equally not familiar
with this option.

On the next page, the output for "FORM.GRADE" is:
389-A,385-B,388-A

My idea here is to strip off the first numbers as the primary key, then
strip off the grade, and rename the "FORM.GRADE" as the remaining
primary keys and grades and repeat through a do while loop WHILE
FORM.GRADE IS NOT "".  Here is the code I am using for this:

<cfset grade = #FORM.grade#>

<cfset gradeSpaces = Replace(grade, "-", " ", "all")> <cfset
characterFour = MID(gradeSpaces, 4, 1)> <cfset characterFive =
MID(gradeSpaces, 5, 1)> <cfset characterSix = MID(gradeSpaces, 6, 1)>

<cfif characterFour IS " ">
   <cfset pKey = LEFT(gradeSpaces, 3)>
   <cfset pKeyGrade = Mid(gradeSpaces, 5, 1)>
   <cfset gradeLength = LEN(gradeSpaces)>
   <cfset grade = MID(gradeSpaces, 7, #gradeLength#)> <cfelseif
characterFive IS " ">
   <cfset pKey = LEFT(gradeSpaces, 4)>
   <cfset pKeyGrade = Mid(gradeSpaces, 6, 1)>
   <cfset gradeLength = LEN(gradeSpaces)>
   <cfset grade = MID(gradeSpaces, 8, #gradeLength#)>

<cfelseif characterSix IS " ">
   <cfset pKey = LEFT(gradeSpaces, 5)>
   <cfset pKeyGrade = Mid(gradeSpaces, 7, 1)>
   <cfset gradeLength = LEN(gradeSpaces)>
   <cfset grade = MID(gradeSpaces, 9, #gradeLength#)>   
</cfif>

<cfoutput>
   gradeSpaces = #gradeSpaces#<br />
   pKey = #pKey#<br />
   pKeyGrade = #pKeyGrade#<br />
   grade = #grade#<br />
</cfoutput>     

I get the correct results I am looking for here:

   gradeSpaces = 389 A,385 B,388 A
   pKey = 389
   pKeyGrade = A
   grade = 385 B,388 A

but I don't know how to make it loop?  I tried the following but it
isn't working:

<cfset grade = #FORM.grade#>

<cfscript>
   DO {
      <cfset gradeSpaces = Replace(grade, "-", " ", "all")>
      <cfset characterFour = MID(gradeSpaces, 4, 1)>
      <cfset characterFive = MID(gradeSpaces, 5, 1)>
      <cfset characterSix = MID(gradeSpaces, 6, 1)>

      <cfif characterFour IS " ">
         <cfset pKey = LEFT(gradeSpaces, 3)>
         <cfset pKeyGrade = Mid(gradeSpaces, 5, 1)>
         <cfset gradeLength = LEN(gradeSpaces)>
         <cfset grade = MID(gradeSpaces, 7, #gradeLength#)>
      <cfelseif characterFive IS " ">
         <cfset pKey = LEFT(gradeSpaces, 4)>
         <cfset pKeyGrade = Mid(gradeSpaces, 6, 1)>
         <cfset gradeLength = LEN(gradeSpaces)>
         <cfset grade = MID(gradeSpaces, 8, #gradeLength#)>

      <cfelseif characterSix IS " ">
         <cfset pKey = LEFT(gradeSpaces, 5)>
         <cfset pKeyGrade = Mid(gradeSpaces, 7, 1)>
         <cfset gradeLength = LEN(gradeSpaces)>
         <cfset grade = MID(gradeSpaces, 9, #gradeLength#)>     
      </cfif>

      <cfoutput>
         gradeSpaces = #gradeSpaces#<br />
         pKey = #pKey#<br />
         pKeyGrade = #pKeyGrade#<br />
         grade = #grade#<br />
      </cfoutput>       
   }
   WHILE (grade IS NOT "");
</cfscript>

Any suggestions are appreciated.  Thanks in advance!  P.S.  I will
create an update to the table inside the loop once it is working.

Thanks again!



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Macromedia ColdFusion MX7
Upgrade to MX7 & experience time-saving features, more productivity.
http://www.adobe.com/products/coldfusion?sdid=RVJW

Archive: 
http://www.houseoffusion.com/groups/CF-Newbie/message.cfm/messageid:2853
Subscription: http://www.houseoffusion.com/groups/CF-Newbie/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.15

Reply via email to