Thanks for the feedback ejgeske. I realize it's a bit confusing and difficult to implement. I wrote this years ago using the phpBB2 database class, so that explains the $db->sql_fetchrow. You have to download phpBB2 and grab the db/mysql.php and includes/db.php files to instigate the $db class. Or you could modify all the $db calls to work with your favorite database class.
There is only one table in this example. The "cat_long_title" doesn't even get used and isn't necessary at all. I'm not even sure why it made it into this snippet. The table only needs the following fields:
cat_id
cat_title
cat_parent_id
The depth is calculated in the code.
I hope this clears up any confusion and let me know if you have any luck with it.