I'm working on a site where a user could select certain dates that apply to them, e.g Date 1,Date 2, Date 3, etc.
Each date will have certain questions belonging to it, so if the customer checked off 'Date 1' to indicate that this date applies to him, he'll then see a bunch of textboxes asking him about Date 1 and how it applies to them. Same goes for all other dates.
Date 1 and 2 and several questions, but the remaining dates have just 1 question.
These dates and their answers will later be used to create personalized reminders for the customer and sent out to him.
I'd also like a design which makes it simple (or as simple as possible) to add additional dates and fields.
My question is, what's the best way to store all the dates and their answers related to the user in the database? I was thinking that in the user
table, I have boolean
columns from Date 1 - Last date (obviously they're not actually named date 1, date 2 etc). If the column for Date 1 is set to 0, it means the customer didn't check it off, and if its 1 then it means he did and he answered the questions for it.
Regarding the actual storage of the dates, I'm considering these two options:
1) 1 table for each date, with columns for every question asked for that date and a user_id
column. So in Date_1
table I'll have columns like Q1_name
, Q2_name
and the answers of the questions that the user gave.
But I want something more elegant because 1), it will make it a pain to fetch all the user's answers when calculating what info. applies to them when sending the personalized emails. 2) Some dates have only 1 question, so it'll be ugly to create a full-blown table for them.
2) A user_answer
table, with the columns:
user_id,date_name,question_name,answer_val
2 seems the most elegant so far, but there should be a better solution. Any thoughts?