Mysql
 sql >> Database >  >> RDS >> Mysql

PHP MySql:stampa albero - casella di controllo padre figlio

Usa la ricorsione! Nota:il codice seguente non è sicuro per i grafici ciclici (i nodi potrebbero non essere antenati di se stessi)!

printChildren($items,0);
function printChildren(array $items, $parentId){
    foreach($items as $item){
        if($item['parent']==$parentId){
            print '<li>';
            print $item['label']; //or whatever you want about the current node
            print '<ul>';
            printChildren($items, $item['id']);
            print '</ul></li>';
        }
    }
}