I want to create JSON object using tow query in PHP , Then retrieve this object using ajax . where the first one will return all users . the second nested query will return all tasks associated to particular user . The structure must be like this :
{
[
user1 : { "name" : "name1"
"task" : [ { "taskname":"taskname1.1" , "date":"1-1" } ,
{ "taskname":"taskname1.2" , "date":"1-1" }
}
} ,
user2: { "name" : "name2"
"task" : [ { "taskname":"taskname2.1" , "date":"2-2" } ,
{ "taskname":"taskname2.2" , "date":"2-2" }
]
}
...
]
}
my problem is :
when I try to parse each user’s tasks , I found that :
each user’s tasks are merged with the Previous user(s)’ tasks .
So what is the best way to create JSON object with the same structure of mine using php ?
— update —
Thanks for everyone who answer me . But I need to know how to create this dynamically , I know how to do this in static and I use json_encode() correctly before , this is not my problem . I really appreciate your answers but this is not what I need and I think the problem is in my question .
Then use JSON encode to send the JSON string.