problem in counting children category
- by moustafa
I have this table:
fourn_category (id , sub)
I am using this code to count:
function CountSub($id){
$root = array($id);
$query = mysql_query("SELECT id FROM fourn_category WHERE sub = '$id'");
while( $row = mysql_fetch_array( $query, MYSQL_ASSOC ) ){
array_push($root,$row['id']);
CountSub($row['id']);
}
return implode(",",$root);
}
It returns the category id as 1,2,3,4,5 to using it to count the sub by IN()
But the problem is that it counts this:
category 1 category 2 category 3 category 4 category 5
Category 1 has 1 child not 4.
Why? How can I get all children's trees?