Writing a Parent-Child Query Sorter in CF, Part 1
Oct 11
Table of contents for CFTreeQuerySort
- Writing a Parent-Child Query Sorter in CF, Part 1
- Writing a Parent-Child Query Sorter in CF, Part 2
- Writing a Parent-Child Query Sorter in CF, Part 3
- Writing a Parent-Child Query Sorter in CF, Part 4
- Writing a Parent-Child Query Sorter in CF, Part 5
- Writing a Parent-Child Query Sorter in CF, Part 6
- Writing a Parent-Child Query Sorter in CF, Part 7
- Writing a Parent-Child Query Sorter in CF, Part 8
- Writing a Parent-Child Query Sorter in CF, Part 9
- Writing a Parent-Child Query Sorter in CF, Part 10
- Writing a Parent-Child Query Sorter in CF, Part 11
- Parent-Child Queries Enhancement: Stacked Numbering
- Parent-Child Queries Enhancement: Multi-Parented Items
- Tree Query Sorter series now available as PDF
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:
| Stuff | ||
|---|---|---|
| ItemID | Title | ParentID |
| 12 | Coding | 0 |
| 26 | Web | 12 |
| 15 | Applications | 12 |
| 9 | Hybrid | 12 |
| 7 | Food | 0 |
| 8 | C++ | 15 |
| 19 | Perl | 9 |
| 16 | ColdFusion | 26 |
| 1 | Cheese | 7 |
This should magically yield a list that looks like this:
- Coding
- Applications
- C++
- Hybrid
- Perl
- Web
- ColdFusion
- Applications
- Food
- Cheese
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.







