I have mysql table with fields:
id | building | title | parent
And I want to create timeline calendar through fullcalendar.io.
I need to create this:
{ id: '1', building: '460 Bryant', title: 'Auditorium D', children: [
{ id: '2', title: 'Room D1' },
{ id: '3', title: 'Room D2' }
] }, etc...
I did this:
$query = "SELECT * FROM resources ORDER BY id";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
foreach($result as $row)
{
$data[] = array(
'id' => $row['id'],
'building' => $row['building'],
'title' => $row['title']
);
}
How can I add to this array element "children" in which all element will be collacted with same 'parent'? Thank you!