In my database I have multiple columns like this
Questions
question one with questionID 1
question two with questionID 2
...
Answers
answer one with questionID 1
answer two with questionID 1
answer one with questionID 2
answer two with questionID 2
To retrieve them I usually works as the example below:
$sql = "SELECT * FROM Questions LEFT JOIN Answers ON Questions.questionID = Answers.questionID";
getting this outcome:
[{
"questionID": "1",
"question": "Test Question",
"potID": "1",
"optionID": "1",
"optionValue": "answer 1",
"isCorrect": "0"
}, {
"questionID": "1",
"question": "Test Question",
"potID": "1",
"optionID": "2",
"optionValue": "answer 2",
"isCorrect": "1"
}]
How can I get the data as following
[{
"questionID": "1",
"question": "Test Question",
"potID": "1"
{Answers: [
"optionID": "1",
"optionValue": "answer 1",
"isCorrect": "0"
}, {
"optionID": "2",
"optionValue": "answer 2",
"isCorrect": "1"
]}
}]