Furthering tbach2's post; the line
$catpath .= show_subcats($cat_id=$category["cat_id"], $prev_path="$catpath");
will be the one causing you grief because it
sets $cat_id to $category['cat_id'],
sets $prev_path to "$catpath", then
-
passes $cat_id and $prev_path as the first two arguments of show_subcats() - the first two arguments being $cat_id and $splitter.
Yes, I know you can do it like this in Perl, but PHP don't play like that.
I suspect
$catpath .= show_subcats($category["cat_id"], $splitter, $catpath);
is what you're intending here. However, I won't say whether such a change will make it actually work.
Incidentally, since you're only using the cat_name and cat_id from the table, things will go much faster if that's all you actually SELECT, instead of selecting everything with *. How much faster depends on how much else is in that table.