Page 1 of 1

phpQuiz

Posted: Sun Jun 01, 2003 11:17 am
by ampersand
I wanna make my own php quiz, but I'm not sure how I should make the database setup.

Should I make 3 tables, 1 with the questions, 1 with the alternatives and the last one containing the id of the question and the id of the righ answer ? is this a good way or is there a more easy way to do this ?

Thanks in advance
Best Regards
@mpersand

Posted: Sun Jun 01, 2003 1:30 pm
by AVATAr
maybe you need only two tables.

One with your questions, and one with the answers, and in this one mark the correct answer with some field

Table_Questions
QuId // id
QuTxt //Texto of the Question

Table_Answers
AnsId // id
AnsTxt // Text of the answer
AnsCorrect //check it if it is the correct answer
QuId // The id of the question

Posted: Sun Jun 01, 2003 5:12 pm
by McGruff
I'd probably just use a single table with columns for id (auto-increment, primary key) question, options, and answer.

In the options column, separate each option with # or etc and explode() to get individual options.

A LIKE search can compare the submitted answer with the table answer.

Posted: Sun Jun 01, 2003 6:44 pm
by nielsene
I think AVATAr suggestion is good. I would avoid McGruff's.

Sticking multiple options within a single column using a deliminator is practically a "repeating group" one of the big no-no's of database desing. (The table is not even in First Normal Form.) It will make adding/ reordering/ updating answer options very difficult compared to a proper design. It also makes it harder to generate stats on the quiz. If you want to preform aggregate queries to count the number of options for each question, a simple SQL query could do it with a proper design, but not with the deliminator based design.

The design also "hides" information from the database and hence violates the "Information Principle" which is possibly the most important design guideline in database design. It basically says nothing should have implicit meaning -- nothing hidden from the database.