Jump to content

Recommended Posts

Hi,

 

I'm trying to implement a quiz but i don't want all the questions on a single page.i want one question appearing after another (similar to a image sideshow) and need to capture that data in MYSQL database.I have got the basics done like all the questions on a single page.What I need to do is get the questionnaire sideshow so that the questions appear one after the other.Can anyone tell me if they have done a similar thing or have found source codes.Help is highly appreciated.Thanks

Look into the PHP session, it is how you maintain state in an applcation.

 

Print question 1, and have the answer "submit" to the same page.  Store the "current" question in the session (or in a hidden variable in the form itself).  Print the next question when you receive the answer to the previous question.  It can all be done in one page:

$nextQuestion = 1;
if ( isset( $_POST['answer'] ) )
{
  //record their answer in the db.
  $nextQuestion = $_POST['questionId'] + 1;
}

//select and display the question in $nextQuestion, including the questionId in the form.
//If there is no next question (you've hit the end of the test), display the score or "thank you" or whatever

As you can see, you don't need sessions for this, but you could use the session as a temporary data store for the answers until the quiz is complete (avoiding a round-trip to the database). 

 

-Dan

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.