Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. //initialise attempt variable
  2. $attempt = 1;
  3.  
  4. $attemptsQuery =
  5. "SELECT studentnumber, MAX(attempt)
  6. FROM attempts
  7. GROUP BY studentnumber";
  8.  
  9. $insertQuery =
  10. "INSERT INTO attempts VALUES (
  11. $date, $firstname, $lastname, $student, $attempt, $quizresult
  12. )";
  13.  
  14. $attemptsResult = mysqli_query($conn, $attemptsQuery);
  15.  
  16. if (mysqli_num_rows($attemptsResult)) == 0) {
  17. mysqli_query($conn, $insertQuery);
  18. echo "<a href=\"quiz.php\"> Click here to resit </a>";
  19. } else {
  20. while ($maxAttempt = mysqli_fetch_assoc($attemptResult)) {
  21.  
  22. if (($maxAttempt["studentnumber"] == $student) && ($maxAttempt["MAX(attempt)"] < 2)) {
  23. $attempt = $maxAttempt["MAX(attempt)"] + 1;
  24. mysqli_query($conn, $insertQuery);
  25. echo "<a href=\"quiz.php\"> Click here to resit </a>";
  26. break;
  27. } else if (($maxAttempt["studentnumber"] == $student) && ($maxAttempt["MAX(attempt)"] >= 2)) {
  28. echo "<p> You have run out of attempts </p>";
  29. break;
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement