It's actually pretty simple, and you don't even need that many columns.
All you need in your table is:
NodeID (the identifier for the node)
NodeParentID (that node's parent, if the node is a root node, just leave it
null or designate a special value)
To dig up and print all sub-levels for any given node, just run the following
recursive function as such:
<pseudocode>
Function GetChildNodes(NodeID)
sql = Select * from table where parentID = " & NodeID
execute sql into new datatable
for each currentrow in datatable
print node info
GetChildNodes(currentrow("NodeID"))
loop
End Function
</pseudocode>
Remember that if you have a ton of nodes with many levels and subnodes,
performance takes a big hit. If you want to limit the levels, you can add a
counter integer paramenter into the function and pass the increment to only dig
as many levels as the counter limit.
Good luck!
-Matias
Manassas, VA
________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf
Of Mike Appenzellar
Sent: Thursday, September 29, 2005 5:58 PM
To: [email protected]
Subject: Re: [AspNetAnyQuestionIsOk] unlimited nesting
That is exactly how my table is setup, but I dont' really see how to
implement it with the loops, etc. The link you sent unforuntately doens't
tell me much.
On 9/29/05, Dean Fiala <[EMAIL PROTECTED]> wrote:
>
> Simple form, infinite levels. All you need are three columns
>
> ID
> Parent ID
> Desc
>
> ID Parent ID Desc
> -----------------------------------
> 1 -1 Root
> 2 1 First Child
> 3 1 Second Child
> 4 3 Grandchild A
> 5 3 Grandchild B
> etc...
>
> You can walk the hierarchy in either direction.
>
> Check out tree walking, recursive trees, etc. For example,
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvbadev/html/traversingtreewalkingcode.asp
>
>
> On 9/29/05, Charles Carroll <[EMAIL PROTECTED]> wrote:
> > Recursion. Research it.
> >
> > On 9/29/05, Mike Appenzellar <[EMAIL PROTECTED]> wrote:
> > >
> > > I have a database structure setup as follows:
> > > ID NAME PID
> > > 1 Level1 0
> > > 2 Level2 0
> > > 3 Level3 0
> > > 4 SubLevel1 1
> > > 5 SubLevel2 2
> > > 6. SubSub1 4
> > > and so on...
> > > Right now I have nested loops that take care of this BUT the problem
> is
> > > that I have to pre-plan on how many potential levels there might be. I
> > > would
> > > like to somehow right my queries or loops to plan for an unlimitied
> amount
> > > of levels.....any ideas?
> >
> >
> > [Non-text portions of this message have been removed]
> >
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
> >
>
>
> --
> Dean Fiala
> Very Practical Software, Inc
> http://www.vpsw.com
>
> ------------------------------
> YAHOO! GROUPS LINKS
>
>
> - Visit your group
> "AspNetAnyQuestionIsOk<http://groups.yahoo.com/group/AspNetAnyQuestionIsOk>"
> on the web.
> - To unsubscribe from this group, send an email to:
> [EMAIL PROTECTED]<[EMAIL PROTECTED]>
> - Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> Service <http://docs.yahoo.com/info/terms/>.
>
>
> ------------------------------
>
[Non-text portions of this message have been removed]
________________________________
YAHOO! GROUPS LINKS
* Visit your group "AspNetAnyQuestionIsOk
<http://groups.yahoo.com/group/AspNetAnyQuestionIsOk> " on the web.
* To unsubscribe from this group, send an email to:
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
* Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
<http://docs.yahoo.com/info/terms/> .
________________________________
[Non-text portions of this message have been removed]
------------------------ Yahoo! Groups Sponsor --------------------~-->
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/saFolB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/