Re: Dynamically building nested unordered lists
Sure. In your example, though, my concern would be that other than the order in which you've listed the items, there's no way to tell which element lower than level 1 is a child of which other element. Do you have a parent ID field or some such that relates an item to its parent item or are you relying on the query returning things in the proper order? The latter seems iffy to me. But, if you have a way of knowing, then you could use simple recursion to build your list: Loop over each level 1 item, find its children and loop over them to find their children and loop over them, etc. Doesn't matter how many levels deep except with respect to performance. Quick pseudo-code: FUNCTION buildNestedList ( [parent] ) get elements of the specified parent (default to no parent) FOR each element write UL write LI write element title IF element has children call buildNestedList ( currentElement ) END IF write /LI write /UL END FOR END FUNCTION This was done very quickly, but may give you enough to work with. On 6/6/06, Everett, Al (NIH/NIGMS) [C] [EMAIL PROTECTED] wrote: Okay, I know that this should be relatively simple, and, in fact, in a previous job I did something similar, but I cannot for the life of me figure out how to do it. My query result looks like this: LVLTITLE 1 Title1 2Subtitle1 1Title2 1Title3 2Subtitle2 2Subtitle3 3Subsubtitle1 1Title4 And I want to turn it into this: ul li Title1 ul liSubtitle1/li /ul /li li Title2 /li li Title3 ul liSubtitle2/li li Subtitle3 ul liSubsubtitle1/li /ul /li /ul /li li Title4 /li /ul The data doesn't support a level higher than 3, so the list cannot nest further than that. Anybody ever done anything similar? ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:242653 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
RE: Dynamically building nested unordered lists
Sure. In your example, though, my concern would be that other than the order in which you've listed the items, there's no way to tell which element lower than level 1 is a child of which other element. Do you have a parent ID field or some such that relates an item to its parent item or are you relying on the query returning things in the proper order? The latter seems iffy to me. Indeed, the query takes care of it. SELECT HDR_ID, HDR_PARENT_ID, HDR_TITLE, LEVEL FROM myTable START WITH HDR_PARENT_ID IS NULL CONNECT BY PRIOR HDR_ID=HDR_PARENT_ID ORDER SIBLINGS BY HDR_SORT_ORDER But, if you have a way of knowing, then you could use simple recursion to build your list: Loop over each level 1 item, find its children and loop over them to find their children and loop over them, etc. Doesn't matter how many levels deep except with respect to performance. I was hoping to avoid recursion, actually. I'll absorb your suggestion though. Since this can't nest very deeply I'm probably over thinking it and should just go with a couple of QofQs. Thanks. ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:242661 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54
RE: Dynamically building nested unordered lists
I have not studied your example but I believe what you are trying to do is what the group by parameter of the cfoutput tag is for. cfoutput query=aQuery group=aField Output stuff that will appear once per unique value of aField. cfoutput Output stuff that will appear once per record in aQuery. /cfoutput Output stuff that will appear once per unique value of aField. /cfoutput -- Ian Skinner Web Programmer BloodSource www.BloodSource.org Sacramento, CA - | 1 | | - Binary Soduko | | | - C code. C code run. Run code run. Please! - Cynthia Dunning Confidentiality Notice: This message including any attachments is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender and delete any copies of this message. ~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:242674 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations Support: http://www.houseoffusion.com/tiny.cfm/54