views:

52

answers:

2

I am working on a site that has tests users can take. I have a test area set up with 100 questions on each subject. If a user is taking a test, I want them to be able to save the work they have already done and when they return I want them to be able to continue the work from where they left. The questions being answer are multiple choice questions and they answer them by selecting the radio button and each radio button has a value of A, B, C, D, or E. I am using PHP and MySQL for my programming and database storage.

Would I need a table for each test and have 100 column names such as 1,2,3,4,5 all the way up to one hundred and when the user saves their work it will store the questions they have completed in the database? Is this a good method or is their another way of doing this?

+5  A: 

Have a table for 'users' and a table for 'questions'.

Have another table, 'answers', with a foreign key to 'questions', a foreign key to 'users' and a column called 'answer'.

When the user answers a question, insert a record into the 'answers' table with the user id, the question id and the answer they provided.

If they have not yet answered the question, then there will not be a record in this table.

Evernoob
Yes. This is called a junction table
Matt Williamson
+1  A: 

This is what I've come up with for a first Draft.

User
--------
UserId
UserName

Test
-------
TestId
TestName

TestQuestions
----------------
QuestionId
TestId
QuestionName

QuestionChoices
----------------
ChoiceId
QuestionId
Choice

UserTestAnswers
-----------
UserId
ChoiceId
Abe Miessler