query("SELECT COUNT(*) FROM students")->fetch(PDO::FETCH_NUM)[0] == 0) { block("red", "no students registered"); exit; } block("black", "summary of everything for " . date("d.m.Y H:i")); $result = $db->query("SELECT firstname, lastname, mnumber, blackboard FROM students ORDER BY LOWER(lastname)"); print "
First name | Last name | Matr.nummer | Blackboard | Examples | Exams | "; while ($student = $result->fetch(PDO::FETCH_ASSOC)) { $totexdone = 0; if( $db->query("SELECT COUNT(*) FROM workdone WHERE mnumber=" . $student['mnumber'])->fetch(PDO::FETCH_NUM)[0] > 0 ) { $exdone = $db->query("SELECT manydone FROM workdone WHERE mnumber=" . $student['mnumber']); while ( $subdone = $exdone->fetch(PDO::FETCH_NUM) ) { $totexdone += $subdone[0]; } } $examscore=0; foreach ($EXAMS as $exam) { $scorestr = $db->query("SELECT scorestr FROM examscore WHERE mnumber=" . $student['mnumber'] . " AND exam=" . $exam['id'])->fetch(PDO::FETCH_NUM)[0]; if ($scorestr != "") { $singlescore = 0; foreach (explode(',',$scorestr) as $points) { $singlescore = $singlescore + $points; } $examscore = $examscore + $singlescore/$exam['totscore']; } } $examscore = ($examscore / $EXAMS_n)*100; print "
" . $student['firstname'] . " | "; print "" . $student['lastname'] . " | "; print "" . $student['mnumber'] . " | "; print ""; print($student['blackboard']); print " | "; print ""; printf("%3d", round(100 * floatval($totexdone) / floatval($SESSIONS_totex_nextinc))); print "% | "; print ""; printf("%3d", round($examscore)); print "% | "; print "