I have a query that returns rows in the following format:
ID NAME PARENTID
1 Top level. 0
7 Second level1. 1
10 Third Level under Second Level1. 7
22 Second Level2. 1
23 Third Level1 under Second Level2. 22
24 Third level2 under Second Level2. 22
What I want to do is dynamically build a structure. The above data would need to be organized in the following hierarchy:
Top Level.
Second Level1.
Third Level under Second Level1.
Second Level2.
Third Level under Second Level2.
Third Level under Second Level2.
The data could be anything and there is no limit to the depth of the hierarchy. I’m looking for a programmatic way of organizing this data into a structure no matter what is returned from the query. I’m writing this in ColdFusion so if you have CF examples that would be nice but pseudocode would be fine. Thanks for the help.
Call this function and pass in 0 for the parentID and the query result for q_query.