Lets say I have a table with "Groups of Questions"
GroupID | value --------+------ 42 | How often do you 9071 | Other question ...
And, for each group of questions I have "questions" and "possible answers"
Group | QuestionID | value ------+------------+------ 42 | 5 | ... brush your teeth? 42 | 89 | ... go to the movies? 9071 | 709 | ... another question ... ...
Group | Answer | value ------+--------+------ 42 | 134 | several times per day 42 | 135 | twice a day 42 | 71 | once a day 42 | 803 | every other day 42 | 8 | once a week 42 | 666 | once a month ...
Now, in PHP/HTML, I do a (virtual) full cross product of questions and possible answers of group 42 to build a 2-entry table where the user will select his/her answers (HTML version)
How often do you | N/d | 2/d | 1/d | d*2 | 1/w | 1/m | ----------------------+-----+-----+-----+-----+-----+-----+ ... brush your teeth? | ( ) | (X) | ( ) | ( ) | ( ) | ( ) | ... go to the movies? | ( ) | ( ) | ( ) | ( ) | (X) | ( ) |
I know I'll need to
insert into answers (question, answer, ...) values (5, 135, ...)
for teeth
and
insert into answers (question, answer, ...) values (89, 8, ...)
for movies
The question is: is there a way to enforce that both question and answer, in the answers
table, "belong" to the same group of questions?
I'd like that
insert into answers (question, answer, ...) values (709, 71, ...)
be disallowed, because question 709 "belongs" to group 9071 and answer 71 belongs to group 42.