I have Adjacency list mode structure like that and i want to count all title of parent like Food = 9, Fruit = 6

For count title using that function
function display_children($parent, $level)
{
$result = mysql_query('SELECT title FROM tree '.'WHERE parent="'.$parent.'"');
while ($row = mysql_fetch_array($result))
{
$data= str_repeat(' ',$level).$row['title']."\n";
echo $data;
$this->display_children($row['title'], $level+1);
}
}
call function
display_children('Food',0);
Result
by echo $data; i m getting right result wht i want, but i want to count all like 9
Fruit Green Peer Red Cherry Yellow Banana Meat Pork
so plz guide how to count all data when i call function
1 Answer