phpQuiz

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ampersand
Forum Commoner
Posts: 54
Joined: Thu Nov 28, 2002 2:00 am
Location: Norway

phpQuiz

Post 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
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post 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
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

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