I'm not sure if this is possible in mysql, but I'm trying to build a nested object out of a query instead of php. I have a db of survey results, and I want to build an object who's keys are the question and value is an array/object of the answers. Is this possible? I'm using something like this:
SELECT
ss.*,
(SELECT int_value FROM `SubmittedQuestions` AS su WHERE ss.id = su.submitted_survey_id)
FROM
`SubmittedSurveys` as ss;
Do I have to build this object in PHP? My issue is that I'm doing all these loops in PHP and I think it's taking a while to build the objects whereas if I could do it in mysql I think it'd be one fast query. Let me know what your thoughts are on this issue.
I'm looking for an object like this:
Survey: { Question 1: [ answer 1, answer 2], Question 2: [ answer 1, answer 2] }
So what I'm currently doing in php is querying all survey questions from one table, then with that object, I loop through and query for each question and get the answers from another table. If there are a lot of questions this design will be super slow, can anybody suggest an alternative?