A method of realizing tree structure without recursion

Source: Internet
Author: User
A method of recursive implementation of tree structure without recursion

The main skill at level (post reply depth) operation

Sunadm in 2000.07.26
____________________________________________
Structure of the Demo table
____________________________________________

Table Name: BBS

Field
Data type
Description ID automatically number Rootidint root post ID, itself as the root Rootid = idfidint parent thread ID, the ID of the post, as the root of the FID = Nulllevelsmallint root post level= 0, other depending on the depth of the reply Subjectchar theme
____________________________________________
SQL Statement (the recordset RS must be created accordingly):
____________________________________________

SELECT *
From BBS
Order by BBS. Rootid DESC, BBS. Level, BBS. FID, BBS. [ID] DESC
____________________________________________
Show the relevant statements for the tree structure:
____________________________________________

Level = 0

Response.Write "<ul>"

While not Rs. Eof

If rs (' level ') < level Then
For i = 1 to Level-1
Response.Write "</ul>"
Next
End If

If rs (' level ') > Level Then
Response.Write "<ul>"
End If
Response.Write "<li>" & RS ("Subject") & "</li>"

Level = rs (' level ')
Rs. MoveNext

Wend

Response.Write "</ul>"
__________________________________________________________
PostScript: Originally I have been using recursion to do this, because I think the main speed bottleneck should be in
Paging above, so always ... Oh! Until today Liao a wake-up.
Hope to be helpful to everybody (throw a few pieces of jade to come over!) Prepare a few sacks for that! :P)
Last Modified 2k-07-26 13:14



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.