PHP/MySQL: How to pull grade scale, instead of value of grade

PHP/MySQL: How to pull grade scale, instead of value of grade

by Tim Tam -
Number of replies: 0

Hey guys. 

I'm working on a site-wide gradebook so that a student can view all of their grades in one place.

It works fairly well but there's one issue.

 

First, here's the code:

 

$con = mysql_connect("localhost","root","root-password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("db-name", $con);

require_login();

$currentuser = $USER->username;

$result = mysql_query("SELECT mdl_user.username, mdl_assignment.name, mdl_assignment_submissions.grade, mdl_course.fullname
FROM mdl_assignment_submissions INNER JOIN mdl_user ON mdl_assignment_submissions.userid = mdl_user.id INNER JOIN mdl_assignment ON

mdl_assignment_submissions.assignment = mdl_assignment.id INNER JOIN mdl_course ON mdl_assignment.course = mdl_course.id
GROUP BY mdl_user.username, mdl_assignment.name, mdl_assignment_submissions.grade, mdl_course.fullname
HAVING mdl_user.username = '$currentuser'
ORDER BY mdl_course.fullname , mdl_assignment.name;",$con);

Print "<table border=1 cellpadding=1 width=900px>";
Print "<tr>";
Print "<td width=300px bgcolor=#C0C0C0><b>Course</b></td>";
Print "<td width=400px bgcolor=#C0C0C0><b>Assignment Name</b></td>";
Print "<td width=75px bgcolor=#C0C0C0><b>Grade</b></td>";

Print "</tr>";
Print "<tr>";
Print "</table>";

Print "<table border=1 cellpadding=1 width=900px>";
while($row = mysql_fetch_array( $result ))
{
Print "<tr>";
Print "<td width=300px>".$row['fullname'] . "</td>";
Print "<td width=400px>".$row['name'] . "</td>";
Print "<td width=75px>".$row['grade'] . "</td>";
//this pulls the grade value.
//Wouldn't it be nice if it displayed the actual grade though? smile

Print "</tr>";
}
Print "</table>";

mysql_close($con);

 

The issue is that because it pulls the grade from the mdl_assignment_submissions table, the grade is a numerical value like -1,2,3,4...etc

 

I want it to display the actual word instead, which is held in the mdl_scale table.

 

But I'm not sure how to link the two.

 

Any ideas as to how I can get it to display the actual grade, rather than the grade value?

 

Thanks smile

Average of ratings: -