function show_subcats($cat_id, $splitter=">", $prev_path="") {
global $catpath;
$cat_sql=mysql_query("SELECT * FROM categories WHERE parent_id=".$cat_id." ORDER BY cat_name");
if (mysql_num_rows($cat_sql)) {
while ($category=mysql_fetch_array($cat_sql)) {
$catpath .= $prev_path.$category["cat_name"].$splitter;
$catpath .= show_subcats($cat_id=$category["cat_id"], $prev_path="$catpath");
}
}
return $catpath;
}
This function is supposed to retrieve all the categories (unlimited depth) from a db by giving a cat_id. The table has parent_id which is 0 for top, cat_id and cat_name.
I call it with show_subcats($cat_id="0")
However it doesn't work as expected. What's the problem with it?
It must return
Cat1
Cat1>Subcat1
Cat1>Subcat1>Subcat2
Cat1>Subcat2
Cat2
.....
and so on
Thanks,
John