1

Got the following tables:

forms
- id
- name
questions
- id
- form_id
- type
- name
questions_translations
- id
- question_id
- lang_id
- label
- placeholder
poss_answers
- id
- question_id
- lang_id
poss_answers_translations
- id
- poss_answer_id
- value

Now I want to select all the questions and possible answers from 1 form, from 1 language. I can easily select all the elements without using the poss_answers_table:

SELECT b.*, f.* FROM app_questions q JOIN app_questions_translations qt ON q.form_id = 4 WHERE lang_id = 4 && qt.question_id = q.id

This gets me all the elements for the two tables, but now I want to add in the poss_answers table. This table holds all the possible answers for a select field, or a checkbox field, or radio field. These are the answers which can be choosen from.

But how can I do that within 1 query?

asked Jul 17, 2015 at 10:57
1
  • Just join the poss_answers table as well. Commented Jul 17, 2015 at 10:59

1 Answer 1

2

Presuming that 1 question (row) has many answers (rows), joining to the answer table will give you the question details returned for every answer row. This is not ideal.
You need to do a 'GetAnswers' query, inside your 'GetQuestions' query, to return all the answers for a particular question.

Something like this..

//'GetQuestions'
foreach($questions as $question)..
 echo $question;
 //'GetAnswers - for Question;
 foreach($answers as $answer)..
 echo $answer;
 //endAnswerLoop
//endQuestionLoop
answered Jul 17, 2015 at 11:06
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, I guess that is it. I was thinking about it earlier but I couldn't get it to work, but I know how to do it now thanks!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.