http://fog.ccsf.cc.ca.us/~tboegel/semesterGPA1.php
我的表格应该计算课程的 GPA(上面的链接)。我仍然需要计算总分、GPA、总质量。我想我可以自己弄清楚,但我需要找出如何 $_REQUEST['course1'], course2, course3, units1, units2, etc...(见下文)
到目前为止,我有
<?php
$course = $_REQUEST['course0'];
$units = $_REQUEST['units0'];
$letterGrade = $_REQUEST['letterGrade0'];
$letterGrade = strtoupper($letterGrade);
if($letterGrade == 'A') {
$numberGrade = 4;
} elseif ($letterGrade == 'B') {
$numberGrade = 3;
} elseif ($letterGrade == 'C') {
$numberGrade = 2;
} elseif ($letterGrade == 'D') {
$numberGrade = 1;
} else {
$numberGrade = 0;
}
$qualityPoints = $units * $numberGrade;
function calculateQualityPoints($course, $units, $letterGrade, $qualityPoints) {
echo "<tr><td>$course</td><td>$units</td><td>$letterGrade</td><td>$qualityPoints</td></tr>";
}
echo "<table width='50%' align='left'><tr><th>Course</th><th>Units</th><th>Letter Grade</th><th>Quality Points</th></tr>";
calculateQualityPoints($course, $units, $letterGrade, $qualityPoints);
echo "<tr><td><strong>Total</strong></td><td><strong>total</strong></td><td></td><td><strong>quality total</strong></td></tr><tr><td><strong>GPA</strong></td><td><strong>GPA #</strong></td></tr></table>";
?>
只有第一个文本框有效。如何获取 course1、course2、course3、units1、units2、letterGrade1 等?
此代码来自 HTML 表单,用于输入课程、年级和单元。
<?php
for ($i=0; $i<5; $i+=1) {
print "<tr>\n";
print "\t<td><input type='text' name='course$i'></td>\n";
print "\t<td><input type='text' name='units$i' size=5></td>\n";
print "\t<td><input type='text' name='letterGrade$i' size=5></td>\n";
print "</tr>\n";
}
?>