If you ever had to save data with a hierarchical structure in a relational database you know is not an easy task. Better, is not easy to do it and obtain performant queries.
The most common approach is to add a field "parent" to our nodes' table. From there it becomes very easy to know who his brothers and his father are... but finding his grandfather or grandnephew requires in the former case to use recursive queries, and in the latter to maintain updated an ordering field. This approach is commonly known as "adjacency model".
The adjacency model doesn't solve many problems (unless using slow recursive queries) as how to obtain the number of a node's descendants or how to delete them all, or how to obtain the path to a node starting from the root. However it excels in moving subtrees.
Nested Set Model (and Baobab) to the rescue.
Nested Set Model is an interesting alternative to the adjacency model. It solves the problems highlighted above, adding some more (but we can often bypass them).
In the Nested Set Model tables have two fields, "left" and "right", that hold a numeric index: the range that these two values identify let us localize a node inside the tree. For example a node's range is always contained inside the range of his antenates; also, the path between the root and a node is composed by the nodes whose interval contains the left index of the reference node.
I'd need time and images to explain thoroughly this model, so I'll invite you to read about it on the page at wikipedia.
The point is that this model let you make searches way quicker than with the traditional model, even if with more difficult queries (and with some limitations: to insert nodes is slow and the trees shouldn't have more than a thousand nodes [but is possible to make forests]).
Baobab is a library (as of today just for PHP and MySQL) that simplifies the creation and management of a tree applying the Nested Set Model. It's extremely easy to use and guarantees an high flexibility. As a matter of fact it's possible to use the PHP interface only or to take advantage of the well documented SQL procedures to create personal search solutions. Moreover is open source and tested, characteristics that I haven't found in many alternatives.
You can learn everything about the library on the dedicated pages, or you can directly go to read the sources at the official Baobab repository.
Have a nice reading