I followed this hierarchical-data-database
but the problem is that I get Fatal error: Maximum function nesting level of ‘100’ reached, I don’t know why.
here is my code
public function display_children($parent,$level){
$cmd = $this->connection->prepare('SELECT user_id,p_id,position from treetbl where p_id= ? order by user_id');
$cmd->execute(array($parent));
$rowdata=array();
while ( $row = $cmd->fetch(PDO::FETCH_ASSOC)) {
$rowdata[] = [['v' => $row['user_id'], 'f' => $row['user_id']], (string)$row['p_id'], $row['user_id']];
$this->display_children($row['p_id'], $level + 1);
}
$cmd = null;
return json_encode($rowdata);
}
here is my table data
user_id p_id
null 1
1 5
1 6
5 7
5 8
7 9
7 10
Thank you in advance.