Ya entendí
Había visto otras maneras similares de hacerlo, pero me descolocó en tu ejemplo el campo "is_parent" para identificar un "jerarca"
Si te sirve modificar un poco la estructura de tu tabla, te paso un ejemplo que modifiqué un poquito del original:
La tabla tiene esta estructura
Código:
RecordID ParentID DisplayName
1 0 Bebidas
2 0 Alimentos
3 1 Frias
4 1 Calientes
5 3 Refrescos
6 2 Hamburgesa
7 4 Café
8 0 Otro Jerarca
9 3 Aguas Frescas
10 7 Irlandés
11 6 Completa
12 7 Americano
Y luego de ejecutar el procedimiento llegás a éste resultado:
Código:
Alimentos
Hamburgesa
Completa
Bebidas
Calientes
Café
Americano
Irlandés
Frias
Aguas Frescas
Refrescos
Otro Jerarca
Código:
<%
Call DoTree(0,0)
'here we initially call the sub routine, we pass 0 as the parent ID
'this will pull all top level parent (meaning they don't have an 'ancestor).
'we also pass 0 for the level, this is used for spacing, or
'making the results appear threaded.
'----------------------------------------------------------
Sub DoTree(ParentID, intLevel)
Set DBConn = Server.CreateObject("ADODB.Connection")
DBConn.Open var_cadena_de_conexion
Dim SQLQ, DBConn, rs, i
SQLQ = "SELECT RecordID, DisplayName FROM RECORDS " & _
"WHERE ParentID = " & ParentID & " ORDER BY DisplayName ASC"
Set rs = DBConn.Execute(SQLQ)
If Not rs.EOF Then
Do Until rs.EOF
' Response.Write "<img src=Spacer.gif Width= " & _
' 15 * intLevel & ">"
Response.Write Replace(Space(intLevel), " ", " ")
Response.Write rs("DisplayName") & "<br>"
'now call the subroutine we're in to see if this value has
'any children and increase the indent, and so on...
DoTree rs("RecordID"), intLevel + 1
rs.MoveNext
Loop
End If
rs.Close
Set rs = Nothing
DBConn.Close
Set DBConn= Nothing
End Sub
'------------------------------------------------------------
%>
Espero te sirva
Saludos y ssalú
PD: Me olvidé de colocar la fuente de donde lo obtuve:
http://www.wwwcoder.com/main/parenti...8/default.aspx