Whether you want to build your own forum, publish the messages from a mailing list on your Website, or write your own cms: there will be a moment that you’ll want to store hierarchical data in a database. And, unless you’re using a XML-like database, tables aren’t hierarchical; they’re just a flat list. You’ll have to find a way to translate the hierarchy in a flat file.
In this (older) article from SitePoint, they give you some wonderful suggetions on how to accomplish this one simple task (heh, simple). Keeping a tree ordered in a flat structure is not an easy task (unless you use the id to parent id method), but they give some good suggestions - like a "Modified Preorder Tree Traversal" and the automation of traversing this structure.
While there are tons of ways to do the same things they say here, this is one of the best I've seen lately - clean, easy to use, and a bit faster than the "id to parent id" I've used as standard.
Thanks to PHPKitchen for the link...




