PHP Calculating GPA and user-defined functions
<p><a href="http://fog.ccsf.cc.ca.us/~tboegel/semesterGPA1.php" rel="nofollow">http://fog.ccsf.cc.ca.us/~tboegel/semesterGPA1.php</a></p>

<p>My form supposed to calculate the GPA of the courses (link above). I still need to calculate total points, GPA, Quality total. I think I can figure it out myself, but I need to find out how to $_REQUEST['course1'], course2, course3, units1, units2, etc... (see below)</p>

<p>So far, I have</p>

<pre><code>&lt;?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 "&lt;tr&gt;&lt;td&gt;$course&lt;/td&gt;&lt;td&gt;$units&lt;/td&gt;&lt;td&gt;$letterGrade&lt;/td&gt;&lt;td&gt;$qualityPoints&lt;/td&gt;&lt;/tr&gt;";

}

echo "&lt;table width='50%' align='left'&gt;&lt;tr&gt;&lt;th&gt;Course&lt;/th&gt;&lt;th&gt;Units&lt;/th&gt;&lt;th&gt;Letter Grade&lt;/th&gt;&lt;th&gt;Quality Points&lt;/th&gt;&lt;/tr&gt;";
calculateQualityPoints($course, $units, $letterGrade, $qualityPoints);                          
echo "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Total&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;strong&gt;total&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;strong&gt;quality total&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;GPA&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;strong&gt;GPA #&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;";                                                                                    

?&gt;
</code></pre>

<p>Only the first text box works. How do I grab course1, course2, course3, units1, units2, letterGrade1, etc?</p>

<p>This code is from the HTML form to input the courses, grade, and units.</p>

<pre><code>&lt;?php
  for ($i=0; $i&lt;5; $i+=1) {
    print "&lt;tr&gt;\n";
    print "\t&lt;td&gt;&lt;input type='text' name='course$i'&gt;&lt;/td&gt;\n";
    print "\t&lt;td&gt;&lt;input type='text' name='units$i' size=5&gt;&lt;/td&gt;\n";
    print "\t&lt;td&gt;&lt;input type='text' name='letterGrade$i' size=5&gt;&lt;/td&gt;\n";
    print "&lt;/tr&gt;\n";
  }
  ?&gt;
</code></pre>
