I'm building a simple quiz PHP app and I have an SQL query that returns the following results:
question_id | question_title | answer_title
1 | your name? | michael
1 | your name? | samuel
2 | your age? | 20
2 | your age? | 21
2 | your age? | 23
Now I want to display each question with its answers in format like this:
<div class="question">
<div>your name?</div>
<div class="answer">michael</div>
<div class="answer">samuel</div>
</div>
<div class="question">
<div>your age?</div>
<div class="answer">20</div>
<div class="answer">21</div>
<div class="answer">22</div>
</div>
I'm using PDO to display MYSQL results. The problem if I loop through the MYSQL results, a question will be displayed multiple times as It's returned in each row. Also don't know how to add the closing DIV tag for the question class after all answers for a certain question are displayed.
Thanks