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