heinkasner Posted May 22, 2012 Share Posted May 22, 2012 I am busy developing an exam-type system where the admin adds questions and answers to those questions into the MySQL database, but really can't think of a way to mark the correct question in the database. I obviously don't want to show the correct question to the student, thus I am trying to think of a way for PHP of which is the correct question to add up the total marks and calculate the percentage. Any help or ideas would be much appreciated. Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/262903-questionnairre-database-design/ Share on other sites More sharing options...
chris-s Posted May 25, 2012 Share Posted May 25, 2012 Why not have a field that says if it's the correct answer? --------------------------------------------------- | id | question_id | answer | correct --------------------------------------------------- | 1 | 1 | Yes | NULL --------------------------------------------------- | 2 | 1 | No | 1 --------------------------------------------------- "No" is the correct answer to question #1... Obviously, don't display the "correct" column to the user... Quote Link to comment https://forums.phpfreaks.com/topic/262903-questionnairre-database-design/#findComment-1348479 Share on other sites More sharing options...
heinkasner Posted May 25, 2012 Author Share Posted May 25, 2012 Hey! Thanks a lot for your reply to my post. Can't believe I have not thought about that way! haha. How would I then determine (in PHP) if the correct answer was chosen or not when the PC marks the questions? Any ideas around that? Thanks a lot! Quote Link to comment https://forums.phpfreaks.com/topic/262903-questionnairre-database-design/#findComment-1348566 Share on other sites More sharing options...
Zimdale Posted June 6, 2012 Share Posted June 6, 2012 Hey! Thanks a lot for your reply to my post. Can't believe I have not thought about that way! haha. How would I then determine (in PHP) if the correct answer was chosen or not when the PC marks the questions? Any ideas around that? Thanks a lot! This is why I usually try to completely avoid having anything "NULL". Why not make it easier with a simple 0 or 1. Then through php all you have to do is check if the answer chosen has a value of one. Could be as easy as a count in sql. SELECT COUNT(*) FROM answer_table WHERE ID=selected_answer_id AND correct=1 if the count turns up 0 you know it's wrong, if it comes up 1 then they got it right, then a simple counter using a session variable can add up the total score at the end. Quote Link to comment https://forums.phpfreaks.com/topic/262903-questionnairre-database-design/#findComment-1351626 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.