Adding a Poll to Your Web Site - Expanding the Poll
(Page 5 of 6 )
What if you want to create a new poll each week, or a 25-question survey, or even a trivia quiz? Simple! Create a second table, poll_questions, to hold all the questions. Add an index to poll_answers to reference the question number.
The SQL for poll_questions might look like this:
CREATE TABLE poll_questions (poll_num INT NOT NULL PRIMARY KEY, question VARCHAR(35) NOT NULL)
And the new poll_answers:
CREATE TABLE poll_answers (poll_num INT NOT NULL, choice INT NOT NULL, activity VARCHAR(35) NOT NULL, votes INT DEFAULT 0, PRIMARY KEY (poll_num, choice))
You could also add date fields to poll_questions to set a starting and ending date for each question to be displayed. If you're designing a quiz, you could add a field to poll_questions to indicate which answer is correct.