id | nameOfPerson | parent
3 | John | NULL
4 | Michel | 3
5 | Husam | 4
6 | Khalaf | 5
7 | Mark | 5
and i want to display it in list like this
John
Michel
Husam
Khalaf
Mark
but in my code he just displayed
John
Michel
How i want to Displeyed all data according to parent like above list ?
this is my function whats the wrongs ?
public function familyTree(){
$query = "SELECT id, nameOfPerson, parent FROM person WHERE parent is null";
$statment = $this->db->prepare($query);
$statment->execute();
echo '<ul id ="family">';
while($family = $statment->fetch(PDO::FETCH_OBJ)){
echo '<li>'. $family->nameOfPerson;
$query1 = "SELECT id, nameOfPerson, parent FROM person WHERE parent = :id";
$statment1 = $this->db->prepare($query1);
$statment1->bindValue('id', $family->id);
$statment1->execute();
if($statment1->rowCount() > 0){
echo '<ul>';
while($family2 = $statment1->fetch(PDO::FETCH_OBJ)){
echo '<li>' . $family2->nameOfPerson . '</li>';
}
echo '</ul>';
}
echo '</li>';
}
echo '</ul>';
}