Im not sure I agree.

with a simple categories table....you can nest as many as you want with
this?

id
categoryName
parentId

<cfquery name = getParents>
select * from categories where parent = 0 order by name
</cfquery>

<UL>
<cfloop query = getParents>

<cfoutput>

<cfif getParents.recordCount>

<---im a parent check for kids --->

<LI>#getParents.name#   

<cfquery name = getChildren>
select * from categories where parentId = getParents.Id
</cfquery>

<cfif getChildren.recordCount>

<UL>
<cfloop query = getChildren>
<LU> #getChildren.Name#         

<---im a child .... might i have kids? --->

<cfquery name = getChildrenOfChildren>
select * from categories where parentId = getChildren.Id
</cfquery>              

<cfif getChildrenOfChildren.recordCount>
<UL>
<cfloop query = getChildrenofChildren>
<LI>#getChildrenofChildren.name#
</cfloop>
</UL>           
</cfif>

</cfloop>
</UL>

</cfif>
</cfif>
</cfoutput>
</cfloop>

</UL>



tony weeg
uncertified advanced cold fusion developer
tony at navtrak dot net
www.navtrak.net
office 410.548.2337
fax 410.860.2337


-----Original Message-----
From: Michael T. Tangorre [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, July 09, 2003 9:48 AM
To: CF-Talk
Subject: Re: Creating a list with infinite groupings and indents


First off... the way you have it setup now will only allow for two
levels.. level 1 and level 2. To get the ability you are after (tree
type strucutre), you need to get into nested sets. Joe Celko has done
some awesome work in this area and the links below may help you out. It
is a bit tricky at first, but once you get it, it is very powerful. The
sql statements for adding/removing/updating "children" or "parents" is
already written in the links below and you can adjust them slightly to
work for your situation. I would definitely start there.

http://www.dbmsmag.com/9603d06.html
http://www.mvps.org/access/queries/qry0023.htm

HTH,

Mike



----- Original Message ----- 
From: "John Sprenkle" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Wednesday, July 09, 2003 9:19 AM
Subject: Creating a list with infinite groupings and indents


> Say I have a table with the following records:
>
> rec id      description          parent id
> 1             Test Record 1      0
> 2             Test Record 2      1
> 3             Test Record 3      1
> 4             Test Record 4      3
> 5             Test Record 5      3
> 6             Test Record 6      4
> 7             Test Record 7      4
> 8             Test Record 8      3
>
> The parent id field relates a record to its parent. I want to display 
> the records in a list so that children records are listed indented 
> under their parent. There can be an infinite number of nested parents 
> and children, so
there
> could be many indents in the list. The output in this example should 
> look
like
> this:
>
> Test Record 1
>       Test Record 2
>       Test Record 3
>             Test Record 4
>                  Test Record 6
>                  Test Record 7
>             Test Record 5
>             Test Record 8
>
> Could somebody give me direction on how to program this? Sample code?
>
> Thank you.
>
>
>
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq

Signup for the Fusion Authority news alert and keep up with the latest news in 
ColdFusion and related topics. 
http://www.fusionauthority.com/signup.cfm

                                Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
                                

Reply via email to