Jump to content

Questionnairre Database Design


heinkasner

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/262903-questionnairre-database-design/
Share on other sites

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...

 

 

  • 2 weeks later...

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.