Visualizzazione dei risultati da 1 a 2 su 2

Discussione: Menu accordion dinamico

  1. #1

    Menu accordion dinamico

    Buon giorno.
    Ho la tabella "tb_menu" strutturata come di seguito:

    id - label - parent
    1 - PRS - 0
    2 - FENDER - 0
    21- Santana - 1
    22- Tremonti - 1
    86- Hendrix - 2
    86- Malmsteen - 2
    90- 1974 - 21
    91- 1975 - 21
    92- AX1 - 22
    93- AX2 - 22

    Devo realizzare un menu accordion.
    Riesco soltanto a visualizzare la voce padre, ma non i figli.
    [php]
    $query= $this->connect->query("SELECT a.id, a.label, a.folder, a.parent,a.link, Deriv1.Count FROM".tb_menu." a
    LEFT OUTER JOIN (SELECT parent, COUNT(*) AS Count FROM ".tb_menu." GROUP BY parent) Deriv1
    ON a.id = Deriv1.parent WHERE a.parent=".$parent);




    $menu_navbar= "<div id='sidebar-wrapper' style='overflow-x: hidden;'>
    <ul class='sidebar-nav' style'font-family:myFirstFont;src: url(../fonts/TitilliumWebRegular/TitilliumWebRegular.woff)'>";
    $menu = array();
    while ($row = mysqli_fetch_assoc($query)) {
    if($row['Count']>0){
    $menu[$row['parent']][] = array($row['label']);
    }
    }
    $i=1;
    $menu_navbar .= "<li class='togliSpazio'><span></span><a href='#' ".($l[0]!='' ? "class='accordion'" : "")." ".(strlen($lista)>=30 ? "style='text-align:left;line-height:18px'" : "").">".
    utf8_encode($lista)."</a>";
    $menu_navbar .= "<ul data-index='".$i."' class='panel togliSpazio'>";


    /*foreach($l as $link){
    $menu_navbar .= "<li>B<a href='/at/".sanitizeLinkAT(utf8_encode($lista))."/".sanitizeLinkAT(utf8_encode($link)).".html?id =$i' ".(strlen($link)>=25 ? "style='text-align:left;line-height:20px;width:90%'" : "").">".
    utf8_encode($link)."</a></li>";
    }*/


    $menu_navbar .= "</ul>
    </li>";
    $i++;
    }
    $menu_navbar.= "</ul>
    </div>";
    //var_dump($menu);
    echo $menu_navbar;
    [/php]

    Come faccio?
    Grazie.



  2. #2
    ho risolto cosi:
    Codice PHP:
    public function display_($parent=0) {        
    $query$this->connect->query("SELECT * FROM ".tb_menu." WHERE parent=".$parent);        
    $i=0;        
    while (
    $row mysqli_fetch_assoc($query)) {            
    if(
    $row['parent']>=0){                
    echo 
    "<li class='togliSpazio'><a ".(strlen($row['label'])>=30 " style='text-align:left;line-height:".($row['parent']>"20px;width:90%" "18px")."'" "")." href='#' ".($row['parent']=="class='accordion'" "").">"utf8_encode($row['label'])."</a>";                
    echo 
    "<ul data-index='".$i."' class='panel togliSpazio'>";            
    }            
    $this->display_($row['id']);           
    echo 
    "</ul></li>";            
    $i++;        
    }    

    Grazie mille.

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 © 2018 vBulletin Solutions, Inc. All rights reserved.