ifis Posted January 16, 2008 Share Posted January 16, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/86332-solved-developing-an-interactive-quiz/ Share on other sites More sharing options...
tomfmason Posted January 16, 2008 Share Posted January 16, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/86332-solved-developing-an-interactive-quiz/#findComment-441129 Share on other sites More sharing options...
Daniel0 Posted January 16, 2008 Share Posted January 16, 2008 Would it be better to do this in another language such as Java? You can make a quiz in any language you would like. Quote Link to comment https://forums.phpfreaks.com/topic/86332-solved-developing-an-interactive-quiz/#findComment-441141 Share on other sites More sharing options...
ifis Posted January 16, 2008 Author Share Posted January 16, 2008 Cool, so it sounds like I should look into AJAX a little but starting to set it up with PHP and MySQL should work fine. As far as learning some AJAX, any suggestions on a good place? w3schools.com? Quote Link to comment https://forums.phpfreaks.com/topic/86332-solved-developing-an-interactive-quiz/#findComment-441193 Share on other sites More sharing options...
Daniel0 Posted January 16, 2008 Share Posted January 16, 2008 For AJAX you really just need to learn Javascript. You could take a look at http://developer.mozilla.org/en/docs/AJAX though. I would recommend you to use Javascript frameworks such as Prototype or jQuery (my favorite). Quote Link to comment https://forums.phpfreaks.com/topic/86332-solved-developing-an-interactive-quiz/#findComment-441200 Share on other sites More sharing options...
dbo Posted January 16, 2008 Share Posted January 16, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/86332-solved-developing-an-interactive-quiz/#findComment-441249 Share on other sites More sharing options...
ifis Posted January 22, 2008 Author Share Posted January 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/86332-solved-developing-an-interactive-quiz/#findComment-446391 Share on other sites More sharing options...
dbo Posted January 22, 2008 Share Posted January 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/86332-solved-developing-an-interactive-quiz/#findComment-446394 Share on other sites More sharing options...
ifis Posted January 22, 2008 Author Share Posted January 22, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/86332-solved-developing-an-interactive-quiz/#findComment-446412 Share on other sites More sharing options...
dbo Posted January 22, 2008 Share Posted January 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/86332-solved-developing-an-interactive-quiz/#findComment-446428 Share on other sites More sharing options...
ifis Posted January 22, 2008 Author Share Posted January 22, 2008 Thanks for the help. Now I just have to put it together, then I'll probably be back asking for somemore help. Quote Link to comment https://forums.phpfreaks.com/topic/86332-solved-developing-an-interactive-quiz/#findComment-446452 Share on other sites More sharing options...
dbo Posted January 22, 2008 Share Posted January 22, 2008 Glad I could help. Start with the database, get it working correctly then worry about writing your application. It will save you a lot of headaches. Quote Link to comment https://forums.phpfreaks.com/topic/86332-solved-developing-an-interactive-quiz/#findComment-446456 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.