http://fog.ccsf.cc.ca.us/~tboegel/semesterGPA1.phpPHP計算GPA和用戶定義的函數
我的形式應該計算課程的GPA(聯繫上文)。我仍然需要計算總積分,GPA,質量總數。我想我可以自己弄清楚,但我需要找出如何$ _REQUEST ['course1'],course2,course3,units1,units2等...(見下文)
到目前爲止,我有
<?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";
}
?>
你可以有'名字= 「當然[]」'和'$ _REQUEST [ '當然']'將是一個陣列,afaicr .. – MiniGod