Co una tabella fai tutto.
tblNames
ID - contatore
name - testo
parentID - numerico
Le voci di primo livello avranno parentID = 0
ID - name - parentID
1 - Sport - 0
2 - Musica - 0
3 - Calcio - 1
4 - Serie A - 3
5 - Champions League - 3
6 - Tennis - 1
7 - Rolland Garros - 6
8 - Heavy Metal - 2
9 - Blues - 2
10 - BB King - 9
11 - Iron Maiden - 8
12 - AS Roma - 4
Con due funzioni ad hoc costruisci il menu ed anche la navigation bar.
codice:
<%
set conn = server.createObject("ADODB.Connection")
conn.open "Provider=sqloledb; " &_
"Network Library=DBMSSOCN; " &_
"Encrypt=yes;" &_
"Data Source=xxxxxxxx;" &_
"Initial Catalog=yyyyyyyy;" &_
"User Id=kkkkkkkk;" &_
"Password=wwwwwwww;"
page = request.serverVariables("PATH_INFO")
id = request.queryString("id")
if len(id) > 0 and isNumeric(id) then
id = cLng(id)
else
id = 0
end if
function buildMenu(theID, theConn)
theSql = "SELECT * FROM tblNames WHERE parentID = " & theID
set theRs = theConn.execute(theSql)
if not theRs.eof then
response.write "<ul>" & vbCrLf
do until theRs.eof
response.write "[*]" & theRs("name") & "" & vbCrLf
call buildmenu(theRs("ID"), theConn)
response.write "" & vbCrLf
theRs.moveNext
loop
response.write "[/list]" & vbCrLf
theRs.Close
set theRs = nothing
else
theRs.close
set theRs = nothing
exit function
end if
end function
function buildNavigationBar(theID, theBaseID, theConn, byRef theNavigationBar)
theSql = "SELECT * FROM tblNames WHERE ID = " & theID
set theRs = theConn.execute(theSql)
if not theRs.eof then
if theBaseID = theRs("ID") then
tempString = theRs("name") & " "
else
tempString = "" & theRs("name") & " "
end if
theNavigationBar = "» " & tempString & theNavigationBar
tempID = theRs("parentID")
theRs.close
set theRs = nothing
call buildNavigationBar(tempID, theBaseID, theConn, theNavigationBar)
else
theRs.close
set theRs = nothing
exit function
end if
end function
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>TITOLO PAGINA</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<%
call buildMenu(0, conn)
call buildNavigationBar(id, id, conn, navigationBar)
response.write navigationBar
%>
</body>
</html>
<%
conn.close
set conn = nothing
%>