I have database with following columns:
id, parent, name, description
The id
has been set to auto incerement. I want to get total number of all the subcategories that are inisde the parent category (which has it's parent set to 0
) I also want this to be reccursive. What can be the fastes way of doing so?
I already wrote the following function but I can not test it at the moment:
function CountDeepSubCategories($parentID, $max = 0)
{
global $_DB;
$all = $all + $max;
$q = $_DB->Query("SELECT id FROM category_cats WHERE parent = $parentID");
$id = $_DB->GetResultValue($q, 0, 'id');
$num = $_DB->GetResultNumber($q);
for($i = 0; $i < $num; $i++)
{
CountDeepSubCategories($id, $all);
}
return $all;
}