I has this function to get root of user and its work .
public function getRootUser()
{
$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;
}
}
And i have this function to get the child of the root , but its not work why?
public function getChildOfParentUser($parentId)
{
$parentId = $family->id;
$query1 = "SELECT id, nameOfPerson, parent FROM person WHERE id = $parentId";
$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>';
}
he give this notice
Notice: Undefined variable: family in /var/www/html/Family.php on line 59
Notice: Trying to get property 'id' of non-object in /var/www/html/Family.php on line 59
Notice: Undefined variable: family in /var/www/html/Family.php on line 62
Notice: Trying to get property 'id' of non-object in /var/www/html/Family.php on line 62
this is some data from my table
id nameOfPerson parent
3 John NULL
4 Michel 3
5 Husam 4
6 Khalaf 5
7 Mark 5
----------------------------