Jump to content

Recommended Posts

I am thinking about develping a quiz for my website.  I have an idea of how to develope it using PHP, cookies, and a mysql database; but I was wondering if there was a better or more elegant way of doing it.  I was going to set a cookie to store the quiz answers then check them when the person "submitted" the quiz.

Also, I was not sure how to randonly select questions from my database using php.  Is there some way to modify a loop?

Would it be better to do this in another language such as Java?

Thanks for the ideas.  I do not want to spend a whole bunch of time working on this just to find out I was doing it the hard way. 

Link to comment
https://forums.phpfreaks.com/topic/86332-solved-developing-an-interactive-quiz/
Share on other sites

php can handle something like this with no problem. However, I would use some javascript(ajax) to get rid of the need for the cookies. As far as random questions you could do something like

$sql = "SELECT `id`,`question` FROM  `table` ORDER BY RAND() LIMIT 5";

 

That should randomly pull 5 questions from the db. You could adjust the limit to suit your needs

How do you define interactive quiz? What are the requirements for this system? It really depends on your vision but I'm not sure that there is necessarily a need for Ajax at all. I would also not store the answers in a cookie.

 

I'd use a setup where a question table (id, question) and answer table (id, question_id, answer, iscorrect). So you have questions, you link possible answers to them, and one or more of them can be correct. So page1 would load up your questions (randomly selected or not), user fills out the form and submits it, you pass the question id and selected answers to page2, page2 determines if the answer is correct or not and acts accordingly.

 

Again, it depends on how you define interactive.

The last response if what I was thinking about doing, but instread of having two pages, use one page with cookies where when the quiz is submitted a cookie will be set with whether each question was right or wrong.  Then I was going to use If statements to either display that the question was right or wrong and have the percentage at the end.  I'm going to try to look up some javascipts that I can modify so I can get around using the cookies.

I'm not sure I totally follow what you're trying to do, but beware using javascript and cookies. If someone is clever enough to figure out how this works they could easily modify the cookies to say they got answers correct that they didn't... same sorta deal with javascript. You need to rely on server side processing to handle this.... preferably a database so that the logic is not hard coded.

So is using a sessions a better/safer way to go?

If someone is clever enough to figure out how this works they could easily modify the cookies to say they got answers correct that they didn't... same sorta deal with javascript. You need to rely on server side processing to handle this

will doing that slow my site down a lot if multiple people are taking a quiz at once?

Obviously database connections can be expensive (takes time), but my guess is that you won't have any problems and probably not even notice the performance impact.

 

You really want to manage this in a database of sorts. Whether that's XML, Flat files, etc is up to you. Personally I'd do it using MySQL just because a relational database is a very natural way of handling this.

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.