Guest User

Untitled

a guest
Feb 19th, 2021
236
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.         include "mysql-connect.php";
  3.  
  4.         date_default_timezone_set("Europe/Bucharest");
  5.         $stmt = $connect->prepare("SELECT DISTINCT exams.course as 'course', exams.examNum as 'examNum', examDate, remarks, submitTime, SUM(exam_answers.score) as 'hisScore' FROM exams, exam_answers
  6.        WHERE graded = 1 and (exams.course = exam_answers.course and exams.examNum = exam_answers.examNum) and studentID = ? ORDER BY examDate DESC, submitTime");
  7.         if (isset($_SESSION["userID"])){
  8.             $stmt->bind_param("s",$_SESSION['userID']);
  9.         } else {
  10.             header("Location: ../php/logout.php");
  11.             $connect->close();
  12.             exit();
  13.         }
  14.         $valid = $stmt->execute();
  15.         if (!$valid){
  16.             die("Could not successfully run query.". $connect->connect_error);
  17.         }
  18.         $result = $stmt->get_result();
  19.         $row = $result->fetch_assoc();
  20.         if ($row['course']==""){
  21.             print '<div class="alert alert-warning"><h4>Opps...</h4><strong>Seems that none of your attempted exams have been graded yet.</strong></div>';
  22.         } else {
  23.             print "<h3>Your Graded Exams</h3>";
  24.             print '<table class="table table-striped table-info"><thead><tr><th>Course Code</th><th>Date</th><th>Submitted Time</th><th>Remarks</th><th>Your Marks</th><th>View in Details</th></tr></thead><tbody>';
  25.             do {
  26.                 $stmt2 = $connect->prepare("SELECT SUM(score) as 'totalScore' FROM exams, exam_questions
  27.                WHERE (exams.course = exam_questions.course and exams.examNum = exam_questions.examNum)
  28.                and exams.course = ? and exams.examNum = ?");
  29.                 $stmt2->bind_param("si",$row['course'],$row['examNum']);
  30.                 $valid = $stmt2->execute();
  31.                 if (!$valid){
  32.                     die("Could not successfully run query.". $connect->connect_error);
  33.                 }
  34.                 $result2 = $stmt2->get_result();
  35.                 $row2 = $result2->fetch_assoc();
  36.                 print "<tr><td>";
  37.                 print $row['course'] . "</td><td>";
  38.                 print $row['examDate'] . "</td><td>";
  39.                 print $row['submitTime'] . "</td><td>";
  40.                 if (strlen($row['remarks'])==0) {
  41.                     print " - </td><td>";
  42.                 } else {
  43.                     print $row['remarks'] . "</td><td>";
  44.                 }
  45.                 print $row['hisScore'] . "/" . $row2['totalScore'] . "</td><td>";
  46.                 print "<a class='btn btn-primary' onclick='ChooseExam(\"".$row['course']."\",".$row['examNum'].");'><i class='fas fa-eye'></i></a></td></tr>";
  47.             } while ($row = $result->fetch_assoc());
  48.             print '</tbody></table>';
  49.         }
  50.        
  51.         $connect->close();
  52. ?>
  53.  
RAW Paste Data