I'm trying to make a json object inside the json object. The json object I desire to make is:
{"post1" : {"id" : "1", "brand" : "brandFromQuery", "model" : "modelFromQuery"},
"post2" : {"id" : "2", "brand" : "brandFromQuery", "model" : "modelFromQuery"},
"post3" : {"id" : "3", "brand" : "brandFromQuery", "model" : "modelFromQuery"},
"post4" : {"id" : "4", "brand" : "brandFromQuery", "model" : "modelFromQuery"}}"
What I ultimately want to do is create a json object as you see above and pass it along to the front end. And the data is the result of SQL query. Each "inner" json object is fetched from the query. Any tip on how I should create this? Would love some efficient solutions for this. I was thinking of doing for loop in a for loop but concerned about the efficiency.
EDIT: I'm trying to use json_encode to achieve this but i'm not sure how to implement this. what i have tried so far is 1) Create JSON object using PHP (creates a class and inputs the data). I really like this method because it is creating a separate class so its more modular but i just cant seem to find a way to create 4 different posts.