Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //initialise attempt variable
- $attempt = 1;
- $attemptsQuery =
- "SELECT studentnumber, MAX(attempt)
- FROM attempts
- GROUP BY studentnumber";
- $insertQuery =
- "INSERT INTO attempts VALUES (
- $date, $firstname, $lastname, $student, $attempt, $quizresult
- )";
- $attemptsResult = mysqli_query($conn, $attemptsQuery);
- if (mysqli_num_rows($attemptsResult)) == 0) {
- mysqli_query($conn, $insertQuery);
- echo "<a href=\"quiz.php\"> Click here to resit </a>";
- } else {
- while ($maxAttempt = mysqli_fetch_assoc($attemptResult)) {
- if (($maxAttempt["studentnumber"] == $student) && ($maxAttempt["MAX(attempt)"] < 2)) {
- $attempt = $maxAttempt["MAX(attempt)"] + 1;
- mysqli_query($conn, $insertQuery);
- echo "<a href=\"quiz.php\"> Click here to resit </a>";
- break;
- } else if (($maxAttempt["studentnumber"] == $student) && ($maxAttempt["MAX(attempt)"] >= 2)) {
- echo "<p> You have run out of attempts </p>";
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement