I have 3 tables in mySQL database.
questions_table with these fields:
- question_id (unique ID for the question)
- question_name (the name of the question)
- question_positionID (the position of
the question, I need this because
the admins are able to change the
positions of the questions in the
html form in the frontend. I use
this to display the questions in the
form appropriately)
questions_users_relationship_table with these fields:
- questions_answers (this is the field
where it stores what the users
answered in the frontend form) - user_id (this is used to connect to
the users table, when loading the
specific user’s answers to the form) - question_id (this is used to
reference the question in the
questions_table)
users_table with these fields:
- user_id (unique id)
- username (as the name implies, username)
- password (as the name implies, password)
So, erm.. The reason why have these 3 tables in the database is because I have to build an admin section on the website which allows the administrators to switch and change the position of the questions in a form. Therefore the reason for the question_positionID field in the questions_table. I have no problem in listing down the questions and its respective answers in the admin section for the administrators to do the position change ( i used ajax drag n drop to update the mysql table on the question_positionID field)..
My problem lies on the frontend html form itself. Because In the database, I only stored the questions and also its answers in its respective tables.. and did not store what type of questions it is (for example: a gender question might use radio buttons for its answers (Male/Female) or maybe address field which has the Country field with answers in the form of a drop down box).. So, in the frontend html form, I am not sure How to list down the questions and its answers for the respective user_id sorted based on the question_positionID and still would properly display the correct form elements (example: questions with dropdown with list the value in the dropdown boxes, questions with answers in radio buttons would be properly checked in the respective radio buttons, and etc etc)..
I believe many people would love to know how to do it.. I not an expert in PHP and mySQL and slowly learning it through examples and online tutorials.. So I would appreciate it if you guys could shed some light on this question of mine..
You should add another table with answers:
Answer
If there are multiple correct answers you will have to add a “is_correct” column to the table as well.
A simple approach to decide how to display the possible answers in the frontend to add a column allow_multiple_answers to your questions_table and decide whether to use dropdown or radio buttons depending on the number of possible answers.
This is just a example. The sollution depends on the framework/template engine you use.