I have an Adjacency model structure in a table, so I got a very good amount of count user_id under parent_id
that the function count user_id under parent_id
function display_children($parent, $level) {
$count = 0;
$result = mysql_query('SELECT user_id FROM sponsers '.'WHERE parent_id="'.$parent.'"');
while ($row = mysql_fetch_array($result))
{
$var = str_repeat(' ',$level).$row['user_id']."\n";
$count += 1 +$this->display_children($row['user_id'], $level+1);
}
return $count;
}
call function
display_children(999, 0)
source
share