RE: [PHP] Polls

From: Date: Mon, 09 Jul 2001 01:05:36 +0000
Subject: RE: [PHP] Polls
Groups: php.general 
Request: Send a blank email to php-general+get-56844@lists.php.net to get a copy of this message
Marius, 2 tables (or more) is definatly the way to approach this... I'd also add an "answerId" column in the Answer table as well so you can primary key it.. for instance. CREATE TABLE questions ( questionId INT NOT NULL, date DATETIME, question TEXT, questionDesc TEXT, PRIMARY KEY questionId ) ; CREATE TABLE answers ( answerId INT NOT NULL, questionId INT NOT NULL, answer INT NOT NULL, PRIMARY KEY answerId ) ; all you have to do then is "SELECT answerId,answer FROM answers WHERE questionId=$phpQuestionId". and thats about it... the 'answers.answer' column could be another type if you dont want and int.. I suggest using that rather than an enum just in case you want 26+ answers to a question... You could use a char or varchar if you like... I also didn't include a date column in the answers table because in the application's sense, they should be tied to the same date.. afterall, how would you design answers for your poll questions dated differently? Also, you can put in a 'sortOrder' column if you don't want the answers to be pulled from your db in order of the answerId or likewise. Keep in mind how you are going to store your response... You will need another table if you are going to capture it to a database.. You'll also need to reference the questionId and answerId (or you can do a join with just the answerId)... Best of Luck! -- Aaron Bennett -----Original Message----- From: Andrew Brampton [mailto:andrew@bramp.freeserve.co.uk] Sent: Sunday, July 08, 2001 6:03 AM To: Marius Pertravcius Cc: php-general@lists.php.net Subject: Re: [PHP] Polls have 2 tables. Questions Table: Question ID Date Question Answers Table: Question ID Answer Then you can make as many answers as you like as long as the Question ID is for your question This make sense? Andrew ----- Original Message ----- From: "Marius Pertravčius" <Lietuva@xxx.lt> To: <php-general@lists.php.net> Sent: Sunday, July 08, 2001 12:31 PM Subject: [PHP] Polls > Sveiki, php-general, > > I'm making some kinf of poll system. I want to use mysql table like > this: > date > question > answer1 > answer2 > answer3 > ..... > answern > > but how to do this table. To write new fields isn't very good. So, > is there any better way? > > > > ____________________________ > 2001.07.08, sekmadienis > Marius Pertravčius > Lietuva@xxx.lt > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#56844) next »