Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2013
    Thanked 0 Times in 0 Posts

    How to calculate results for a complicated multiple choice quiz?

    I've been working on a multiple choice quiz in PHP recently.

    I've noticed that a lot of tutorials online tend to focus on simple one page quizzes. What I'm trying to do is to create a multiple-choice that contain more than one page. The quiz lasts for twelve questions, and each page contains three questions.

    At the moment, I'm trying calculate from 0 to 9 to figure out how many questions I've answered correctly, but I can't calculate any answers. It doesn't matter if I answer the question correctly, in the end I'm always getting a "0/9" as a final score.

    I've uploaded "txt" containing my PHP code, including my final results page if anyone is interested. I'd appreciate any help!
    Attached Files Attached Files
    Last edited by davo398; 08-30-2013 at 04:35 PM.

  2. #2
    Senior Coder
    Join Date
    Sep 2010
    Thanked 275 Times in 275 Posts
    Suggestion, make a folder, put an index.php page in the folder, as the questions are answered, just include different stuff in the page. If you include a file as a .txt it will simply be written verbatim to the page. Use if($_SESSION['whatever']=="somevalue') include "./thisfile.txt"; or php, to set conditions for the includes.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.

    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  3. #3
    New Coder
    Join Date
    Jun 2013
    Thanked 0 Times in 0 Posts

    Thumbs up Solved it!

    I forgot to say thanks to DrDOS for giving me the idea to work it out; I feel like a jerk for not mentioning for so long.

    I thought I'd share what I created. What I did for each quiz page was that I applied the number 1 in the value for the right multiple choice answer (i.e. <input type="radio" value="1"/>). For all the other incorrect answers, I typed in 0 for the values (i.e. <input type="radio" value="0"/>).

    In the final results.php page I called the names of the questions, and then I incremented totalAnswersCorrect to add all the correct answers together. In the end, I divided all the total correct answers out of 12.

    Underneath is my working results.php file.

    PHP Code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Movie Buff Quiz</title>

    //Calculates the correct answers altogether.
    //Determines how many answers are
    echo " ".$totalAnswersCorrect." / 12  ";
    " ";
     if (

    else if(
    "Not good enough. Try again.";
    } else if (
    "Okay $name, but give it another go.";


    Now I need help on another multiple choice quiz, although this time it's a bit more complicated. What I've been trying to do is to create another quiz that loops questions on the same page, instead of multiple pages. Basically, you click on the submit button to go to the next set of questions, but on the same page. Unlike the first project I was working on, the questions are being retrieved from the database. And unlike the other example, I have no idea what code to refer to when trying to calculate answers in the final results page, so I was wondering if someone could help me out. If so, please feel free to look at the attachment containing my quiz.php text file, thanks.
    Attached Files Attached Files
    Last edited by davo398; 10-19-2013 at 03:09 PM.


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts