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!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
ColdFusion MX7 by AdobeĀ®
Dyncamically transform webcontent into Adobe PDF with new ColdFusion MX7.
Free Trial. http://www.adobe.com/products/coldfusion?sdid=RVJV
Archive:
http://www.houseoffusion.com/groups/CF-Newbie/message.cfm/messageid:2852
Subscription: http://www.houseoffusion.com/groups/CF-Newbie/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.15