2

I do want to create a Quiz like on this site

Quiz

How can I done this using php and jQuery? or is there other way to do this not using flash

I do got a idea from this and my problem is how to implement the timer with this

Creating a Quiz with jQuery

answer and made by @Fatih

1 Answer 1

3

Apparently I don't know my router bits; however, making a quiz can be really easy to build (hard-coded) or really hard to build (database-driven). The first is difficult to change later on while the second is quite easy.

It really depends what you want to do, both are quite doable with php and jQuery.

  1. I would setup a database of questions, answers, and user-responses.
  2. Then I'd createa a few php pages, one for the user to view /quiz.php and one for my jQuery to post data to /ajaxhelp.php (accessed by $.post())
  3. ajaxhelp.php would return JSON data based on the post paramaters. Mabye a question + 4 answers for "nextQuestion" then the jQuery would generate the form with a few radio boxes for each answer
  4. The user picks their answer, and then you $.post() it back; ahaxhelp.php checks the database to see if that was marked as the correct answer, and returns the result.
  5. jQuery gets the "nextQuestion" and makes a new form
  6. Display summary of results

edit

After your comment about static data, this simple html page should get you started:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js"></script>

        <script type="text/javascript">
            var q1wa = 
            { 
                Question: 'Question One Text', 
                Answers: 
                [ 
                    { AText: 'Answer1 Text', RightAnswer: true },
                    { AText: 'Answer2 Text', RightAnswer: false },
                    { AText: 'Answer3 Text', RightAnswer: false }
                ]
            };

            $(document).ready(function () {
                $('#question').html(q1wa.Question);
                for(var i = 0; i < q1wa.Answers.length; i++) {
                    $('#answers').append(q1wa.Answers[i].AText + "<br />");
                }

            });
    </script>
    </head>
    <body>
        <div id="question"></div>
        <div id="answers"></div>
    </body> 
</html>

It should be noted, that with this method, your "correct" answer is visible to anyone who cares to do a View Source, but this is a good starting point. It would also not be hard to incorporate a php portion to keep the answer secret by doing answer validation server-side instead of client-side.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the respond 2-6 is exactly what I want to do with but it's a static question that i don't need to have a database like in my example, Do you have any reference site or books that would help on developing this quiz? Thanks for the reply I really apppeciated

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.