One of the Stupid-Web-Programming-Tricks I end up recoding quite often is a sorter for queries with Parent-Child relationships. Trees, basically. You know the situation: some yahoo wants theoretically infinite levels of depth to his navigational menus or his product categories for his e-commerce system. What you end up with is a table in a database that looks like this:
This should magically yield a list that looks like this:
Getting from Point A to Point B isn’t all that hard, especially when you have the time, foresight, and ability to plan ahead. There are dozens of different ways to accomplish this efficiently within the database. Most of the time, however, I find that I have read-only access to the database table and end up having to do the organization in code. In this series of posts I’ll be explaining my solution and how I get to it.