Displaying Preorder Tree Traversal Hierarchy in ASP?

F

FrankEBailey

I've been reading up on Modified Preorder Tree Traversal and it's
definitely ideal for the kind of tree structures I need to model for my
company's multi-level sales hierarchy. I've implemented the database
side already in SQL Server 2000 and can retrieve all child nodes based
on the left and right IDs of the current node. My problem is displaying
the tree so that correct indentation can be used to show the
relationships between the parents and their respective child nodes.

I'm aiming for this type of display:

Organic_Produce
- Fruit
- Banana
- Cherry
- Orange
- Vegetables
- Potatoes
- Savoury Potatoes
- Sweet Potatoes
- Zucchini

etc.

Now, I know a recursive function of some sort is needed, and I read on
this page http://www.sitepoint.com/print/hierarchical-data-database how
to create the function in PHP, however I don't have the first clue how
to translate this into VBScript for implementation in ASP. If anyone
has perhaps an example of how a function to display MPTT-type
hierarchical data via VBScript, I will greatly appreciate any
assistance you might be able to offer.

Thanks in advance!
Frank
 
A

Anthony Jones

I've been reading up on Modified Preorder Tree Traversal and it's
definitely ideal for the kind of tree structures
Now, I know a recursive function of some sort is needed

Actually I think the whole point of the left right values in this technique
is to avoid having recursive functions which can become very slow.

All you need is a single recordset ordered by Left. The code is something
like this:-

Dim lLastLeft
Dim lDepth
Dim alRight

lDepth = 0

lLastLeft = rs("left")

ReDim alRight(4)
alRight(lDepth) = rs("right")

RenderRecord rs, lDepth
rs.MoveNext

Do Until rs.EOF

Do Until alRight(lDepth) > rs("left")
lDepth = lDepth - 1
Loop

If lDepth = UBound(alDepth) Then ReDim Preserve alRight(lDepth * 2)
lDepth = lDepth + 1
alRight(lDepth) = rs("right")

RenderRecord rs, lDepth

rs.MoveNext
Loop

Anthony.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top