Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    Creare albero con sottocategorie

    Salv amici,

    devo creare un menu con categorie e sottocategorie prese da un DB, però non so come impostarlo!

    La mia tabella ha i seguenti campi:

    ID_CAT, ID_SUBCAT, CATEGORIA

    Le categorie principali avranno come valore di ID_SUBCAT -> 0
    quelle che saranno invece sottocategorie avranno valore di ID_SUBCAT = ID_CAT della categoria a cui appartengono...

    COme posso creare un ciclo che mi faccia l'albero di navigazione????

    Tipo:

    VINI
    - bianchi
    - rossi
    - rosati
    - spumanti
    INSACCATI
    - salumi
    - prosciutti
    CONSERVE
    -marmellate
    -agrumi
    -frutta rossa
    - frutta bianca
    - confetture
    - gelatine
    Digital XP - The new expression of digital art! - http://www.mimanchitu.it

  2. #2
    se n'è parlato molto nel forum e ci sono anche esempi, cmq è un algoritmo non proprio semplicissimo se lo si cerca di ottimizzare...

    buona ricerca
    IP-PBX management: http://www.easypbx.it

    Old account: 2126 messages
    Oldest account: 3559 messages

  3. #3

    allora

    Allora cercando qua e la ho trovato questo script:

    codice:
    <%
    
    Function MenuCategorie(ByVal lngId)
    Dim idTmp
    Dim strTmp
    
    myrs.Filter = "ID_CAT=" & lngId
    idTmp = myrs("ID_SUBCAT")
    If idTmp <> 0 Then
      strTmp = myrs("CATEGORIA")
      MenuCategorie =  MenuCategorie(idTmp) & " > " & strTmp 
    Else
      MenuCategorie = MenuCategorie & myrs("CATEGORIA")
    End If
    End Function
    ' Crea e apri il recordset
    strConn = MM_connGestione_STRING
    	Set conn = Server.CreateObject("ADODB.Connection")
    	Conn.open strConn
    sql = "SELECT * FROM dali_categorie"
    Set myrs= Server.CreateObject("ADODB.Recordset")
    myrs.Open sql, conn, 3, 3
    ' Crea il menu
    strMenu = MenuCategorie(3) 
    ' chiusura e distruzione recordset
    myrs.Close
    Set myrs = Nothing
    ' Visualizza il menu
    Response.Write strMenu
    %>
    Che però come risultato mi restituisce solo l voce corrispondente al record con ID_CAT = 3!!!!

    Come faccio ad estrarre tutto l'albero????
    Digital XP - The new expression of digital art! - http://www.mimanchitu.it

  4. #4
    Tabella "tblNames".
    Campi:
    ID - contatore
    name - testo
    parentID - numerico

    Le categorie di primo livello hanno parentID = 0

    codice:
    <%
    
    'on error resume next
    
    set conn = server.createObject("ADODB.Connection")
    
    conn.open	"Provider=sqloledb; " &_
    
    					"Network Library=DBMSSOCN; " &_
    
    					"Encrypt=yes;" &_
    
              "Data Source=localhost;" &_
    
              "Initial Catalog=database;" &_
    
              "User Id=utente;" &_
    
              "Password=password;"
    
    
    
    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 = "&raquo; " & 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
    
    %>

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.