Hi gang

This is possibly insanely simple, but I've been coding on it for the past 11 hours, so my head's gone a little fuzzy.

been through the MySQL manual, but it's not really agreeing with me on finding anything useful...

I've got a table of categories, organised in a tree structure:

table wp_categories
catID int(10) UNSIGNED
parentID int(10) UNSIGNED
rootID int(10) UNSIGNED
level tinyint(3) UNSIGNED
cat_title varchar(255)
cat_desc text

catID being the primary key, parentID the parent's ID, and rootID the ID of the root category of the branch this category belongs to. Level is simply a number as to how deep in the tree the given category is. I only use it to make it simpler to build the graphics.

Here comes the problem: I need to be able to build visually the branch from root to a given folder, using only the given folder's ID as starting point. That is, traversing backwards up the branch from any given folder, and reattaching the branch till the root is reached.

Building the entire tree from root down is easy enough, but for some reason I've got a brainfart as to how I can go backwards.

That said, I know I could probably do this using recursive SQL statements, but I'd rather use as little talking with the DB as possible. The goal is to do this one task with as few SQL calls as entirely possible, preferably 1, 2 at most... since I found building arrays and traversing them is much faster than SQL calls...

the root ID is 0, so any category in root, will have parentID of 0, and rootID of 0.

I figure using the rootID to just pull the relevant branch might be part of it, but my problem comes with reattaching the branch correctly, and finding the root folder and stick the branch to it ... and doing all of this in reverse since that's what I need for the visual part...

Using MySQL btw ...


TIA

Rene
--
Rene Brehmer
aka Metalbunny

If your life was a dream, would you wake up from a nightmare, dripping of sweat, hoping it was over? Or would you wake up happy and pleased, ready to take on the day with a smile?

http://metalbunny.net/
References, tools, and other useful stuff...
Check out the new Metalbunny forums at http://forums.metalbunny.net/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to