csierra
Posts: 123
|
Posted: 12/26/2009, 4:05 PM |
|
Hi there, I´ve just made a small class, cSitemap to grab from the classic Menu table we use to generate complex navigations;
The tbMenu fields are: Menu_Id, Menu_Parent_Id, Title, h_ref
And the class code:
<%
Class cSitemap
Private oConn
Private sList
Private mList
Private lId
Private SQL
Public Function Init
Set oConn = New clsDBcnx_te_front 'clase de codecharge connection
oConn.Open
End Function
Public Function List(oSet)
If oSet.BOF and oSet.EOF Then
Else
sList = sList & "<ul>" & vbLf
Do While Not oSet.EOF
lId=oSet.Fields("Menu_Id").Value
If lid<>0 Then
sList = sList & "<li><a href='" & oSet.Fields("h_ref").Value & "'>" & oSet.Fields("Title").Value & "</a></li>"
'Recursive call
List(SubList(lId))
Else
sList = sList & "<li>" & oSet.Fields("Title").Value & "</li>" & vbLf
End If
oSet.MoveNext
Loop
sList=sList & "</ul>" & vbLf
End If
List = sList
End Function
Public Function SubList(Parent_Id)
If IsNull(Parent_Id) Or Not IsNumeric(Parent_Id) Then
SQL = "SELECT * FROM tbMenu WHERE 0=1"
Else
SQL = "SELECT * FROM tbMenu WHERE Menu_Parent_Id=" & Parent_Id
End If
Set SubList = CreateObject("ADODB.Recordset")
SubList.Open SQL, oConn.Connection
End Function
End Class
%>
Just drop it as an includable, then rename the connection accordingly, and you are ready to go; You just use it as this:
Dim oMap
Set oMap = New cSitemap
oMap.Init
Label1.Value=oMap.List(oMap.SubList(0))
Where label1 should be set as HTML and 0 is my root cat, you could use any Id to show just one category.
Glad to share, comments welcome
_________________
Yes! I Can!!! |