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

 

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.