It's easy way.
Some code:
//select already enroled courses
$query = "
SELECT c.id, c.fullname FROM mdl_course c
INNER JOIN mdl_enrol e ON c.id=e.courseid
INNER JOIN mdl_user_enrolments ue ON e.id=ue.enrolid
WHERE userid={$userid}
ORDER BY c.fullname";
$res = mysql_query($query);
while ( $row = mysql_fetch_array($res) ) {
echo "<b>".$row["id"]." - ".$row["fullname"]."</b><br />";
$courseid = $row["id"];
//select assignments
$query = "
SELECT a.id, a.name FROM mdl_assign a
WHERE course={$courseid}
ORDER BY a.name";
$res2 = mysql_query($query);
while ( $row2 = mysql_fetch_array($res2) ) {
echo "- ".$row2["id"]." - ".$row2["name"];
$asid = $row2["id"];
//select grades
$query = "
SELECT ag.grade FROM mdl_assign_grades ag
WHERE assignment={$asid} AND userid={$userid}
ORDER BY ag.attemptnumber";
$resGrades = mysql_query($query);
echo " (Grades: ";
while ( $rowGrades = mysql_fetch_array($resGrades) ) {
echo $rowGrades["grade"].", ";
}
echo ")";
echo "<br />";
}
}