Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mbpp's avatar
Level 3

Dynamic survey app

Hi there, im creating a app the creates surveys. But im struggling in the database structure.

My Tables:
Surveys:
- id;
- user_id;
- title;
- status;

Questions:
- id;
- survey_id;
- label;
- input_type;
- options;
- order;

My only issue is that i need to be able to create some kind of cascading or populate feature. For example imagine that i have a question (radio button) where the answer have 2 options, "yes" or "no", but in case that the user selects "yes" for example it appears another question. How i would structure my tables?

0 likes
3 replies
khaledSMQ's avatar

what if you link it in the same table like this

Questions:
|->    -id;
|       - survey_id;
|->    - question_id;
        - label;
        - input_type;
        - options;
        - order;
khaledSMQ's avatar

or if the options is dynamic you need to create separate tables

like this

question table
Questions:
- id;
- survey_id;
- label;
- input_type;
- order;

options table
- question_id
- option (name or type or what ever)
- next_qustion_id
mbpp's avatar
Level 3

@khaledSMQ for sure the options will be dynamic, depending of what the user selects, wheater is a selec input, option (checkbox, radio), it could appear another question related.

Please or to participate in this conversation.