This should (hopefully) be a pretty easy question for some of you to answer.
I have a working Recursive menu from a mySQL database, now my main problem is:
What is the best way to create the URL? I would prefer to bring in the title of each row like /eggs/milk/bacon/. Eggs being level 0 like: eggs-0, milk-1, bacon-2. Any ideas on how to dynamicly output this?
I am pretty much going for what "cletus" said a few comments down on this question: PHP/MySQL - building a nav menu hierarchy
But I need a bit more explanation on how to do it.
Unless you plan to modify your menu tree often, pre-storing the required hierarchical URL for each menu item is probably the easiest (for run-time resolution that is).
If you expect the tree to be modified often enough, lets say - through a web interface, then it would be easier to generate the paths every time you read the menu, something like this:
I haven't debugged this code, only tested it for correctness ;-)
Well, if you want a hierarchy, be best method I know of is called "Modified Preorder Tree Traversal" that is described in great detail in this Sitepoint article, starts about halfway down.
The main difference from what Guss suggested is that it's a bit more performant and a lot easier to only fetch the part of the tree you're looking for.
i wrote something in groovy: http://blog.srvme.de/2009/11/29/reading-a-reflexive-association-in-a-recursive-way-for-grails-and-groovy/