Here's how I'm getting my data from database. It is a 3 level hierarchy. Parent, child and children of child.
page_id | parent_id
1 0
2 1
3 0
4 3
The top data shows 0 as the parent.
$id = 0;
public function getHierarchy($id)
{
$Pages = new Pages();
$arr = array();
$result = $Pages->getParent($id);
foreach($result as $p){
$arr[] = array(
'title' => $p['title'],
'children' => $this->getHierarchy($p['page_id']),
);
}
return $arr;
}
So far I'm getting data but it's kinda slow. The browser loads so long before showing the data. How can I make my code faster so it does not take long for the browser to load data?
Thanks.