Originariamente inviato da marco1970
si sono id di altre tabelle.
in pratica ho un menu con infiniti sottomenu e quindi nn posso usare 2 tabelle tipo categoria e sottocategoria.
questo mi serve ad assegnare lo stesso prodotto a + categorie senza reinserirlo nuovamente
Potevi fare una sola tabella con l'aggiunta del campo parentID.
Le voci di primo livello avrebbero avuto parentID = 0
tblNames
ID - contatore
name - testo
parentID - numerico
codice:
ID name parentID
1 Sport 0
2 Cronaca 0
3 Calcio 1
4 Tennis 1
5 Notizie 2
6 Italia 5
7 Estero 5
8 Serie A 3
9 Champions L. 3
10 Roland Gar. 4
11 Golf 1
12 PGA Tour 11
E con queste funzioni costruisci il menu e la barra di navigazione:
codice:
<%
set conn = server.createObject("ADODB.Connection")
conn.open "Provider=sqloledb; " &_
"Network Library=DBMSSOCN; " &_
"Encrypt=yes;" &_
"Data Source=localhost;" &_
"Initial Catalog=samples;" &_
"User Id=xxxxxx;" &_
"Password=xxxxxx;"
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
%>
Provalo.