I have this table
mytree
pid mem
0 1
1 5
1 6
5 7
5 8
7 9
7 10
I have this function to get the data
public function display_children($parent,$level, $rec = array()){
try {
$cmd = $this->connection->prepare('SELECT mem,pid from mytree where pid = ?');
$cmd->execute(array($parent));
while ( $row = $cmd->fetch(PDO::FETCH_ASSOC)) {
$rec[] = [['v' => $row['mem'], 'f' => $row['mem']], (string)$row['pid'], $row['mem']];
$rec = $this->display_children($row['mem'], $level + 1, $rec);
}
}
catch(PDOException $ex){
return $ex->getMessage();
}
return $rec;
}
First call
echo json_encode(display_children(5, 0));
but I only get this result
5 7
5 8
7 9
7 10
How can include the parent id 1 and memberid 5 ?,like this
parentid memid
1 5
Thank you in advance.