Please i need you help my script. I’m generating a new column, whereby a particular score is awarded a grade according to the score.
This query was used to obtain the scores from the main table.
$query8 =mysql_query("SELECT m.score
FROM maintable AS m
INNER JOIN students AS s ON
m.matric_no = s.matric_no
INNER JOIN courses AS c ON
m.course_code = c.course_code
WHERE m.matric_no = '".$matric_no."'
AND m.level = '".$level."'")
or die (mysql_error());
$number_cols1 = mysql_num_fields ($query8);
I’ve being able to generate the grades accordingly, and a new column was added to the HTML Table , but i’m having a problem putting the heading to the new column that was added i.e “Grades”.
Also i’ve noticed that when i update a score and i re-run the results page the grades implementation does to take effect i.e if former score was “80” with grade “A”, and i downgrade to “33” with a grade of “F”, the script still outputs “A”, while the score has changed.
2) I’m also trying to copy all courses that have a grade of “F” into a seperate table. So the student will know courses he/she will have to retake. But my array implementation is not achieving this.
Thank you for you help.
while ($row8 = mysql_fetch_ assoc($query8)) {
if ($row8['score'] >= 70) {
$grade = 'A';
}
elseif ($row8['score'] >= 60) {
$grade = 'B';
}elseif ($row8['score'] >= 50) {
$grade = 'C';
}elseif ($row8['score'] >= 45) {
$grade = 'D';
}elseif($row8['score'] >= 40) {
$grade = 'E';
}else{
$grade = 'F';
} }
echo "<table border = \"2\" cellspacing = \"1\" cellpadding = \"2\" bgcolor = MediumPurple class =\"cambria\" >\n";
echo "<tr align= \"center\">\n";
echo "<th>"; //this echo out
echo"s/n"; //the serial number
echo "</th>\n"; //heading for the table
for ($i=0; $i<$number_cols; $i++) {
echo "<th>" . mysql_field_name ($query7, $i). "</th>\n";
}$serial = 0;
while ($row = mysql_fetch_row ($query7)) {
$serial++;
echo "<tr align=center>\n";
echo"<td>";
echo $serial;
echo"</td>\n";
foreach ($row as $value)
{
echo "<td>$value</td>\n";
}
echo "<td>";
echo $grade ;
echo "</td>\n";
}
for ($i=0; $i<$number_cols; $i++) {
echo "</tr>\n";
echo "</table>";
Please clean up that code, it’s a hideous ugly mess and almost impossible to read through.
That being said, the problem is that you’re setting the letter grade BEFORE you fetch the individual grades. You seem to be using a
query7to fetch grades, but determine the score BEFORE that query is even run, so you output the same letter score for every grade fetched by query7.Look up HEREDOCs, they’ll help eliminate your bad case of ‘leaning toothpick syndrome’ – repeated echoes for output html is horrible for maintainability and legibility.