I have an Adjacency list mode structure and I want to count the entire parent level header, e.g. Food = (2,4,3), Fruit = (3,3)
Tree table structure

after that make a tree like this

with this code I get the right general, as for Food = 9, Fruit = 6
function display_children($parent, $level)
{
$result = mysql_query('SELECT title FROM tree '.'WHERE parent="'.$parent.'"');
$count = 0;
while ($row = mysql_fetch_array($result))
{
$data= str_repeat(' ',$level).$row['title']."\n";
echo $data;
$count += 1 + $this->display_children($row['title'], $level+1);
}
return $count;
}
call function
display_children(Food, 0)
Result: 9 // but I want to get the result, for example, 2,4,3
But I want to get a final final result, for example, for food 2,4,3 and for fruit 3,3 by level
so plz guide how to get the general level
source
share