Mam skrypt do wyświetlania drzewa kategorii ale mam z nim problem ponieważ chcę wyświetlić kategorie w kolumnach. Ale jak jakaś kategoria ma podkategorię to nie tworzy się nowa kolumna tylko dopisuje do tej samej. Prosiłbym o pomoc.
Oto kod:
<?php include "lib/functions.php"; "4" => array ( "id" => "200", "name" => "Agregaty prÄ dotwĂłrcze", "parent_id" => "184", "ip" => "184.200" ), "7" => array ( "id" => "258", "name" => "Gilotyna do bruku", "parent_id" => "184", "ip" => "184.258" ), "9" => array ( "id" => "203", "name" => "Listwy wibracyjne", "parent_id" => "184", "ip" => "184.203" ), "10" => array ( "id" => "205", "name" => "MĹotowiertarki", "parent_id" => "184", "ip" => "184.205" ), "12" => array ( "id" => "207", "name" => "Myjki ciĹnieniowe", "parent_id" => "184", "ip" => "184.207" ), (...) "71" => array ( "id" => "273", "name" => "siala", "parent_id" => "270", "ip" => "265.267.270.273" ) ); $tree = getTree($arr2, 184); $j = 0; $iter = 0; $x = 0; $col = null; foreach ($tree as $sub) { // Jeżeli jest podkategoria to dodaje <ul>, jeżeli nie, zamyka </li> $close = "<ul class=\"none\">"; $hascat = "class=\"hascat\""; } else { $close = "</li>"; $hascat = ""; if($x%10 == 0) $col = "</ul><ul class=\"cat\">"; else $col = null; } echo "<li><a href=\"#\" ".$hascat.">".$sub["name"]." </a>"." <small>".$sub["ip"]."; ".$x."</small>"; } //Zamyka ul i li tyle razy ile trzeba for($i1=$tree[$j+1]["level"]; $i1<$sub["level"]; $i1++) { } } //Zamyka ul, li na końcu for($i2=0; $i2<$sub["level"]; $i2++) { } } $j++; } ?>
Kod funkcji getTree()
<?php function getTree($cat = null, $parentId = 0, $level = 0, $result = null){ if ($result == null) if ($cat == null) { exit; } foreach ($cat as $kat) { if ($kat["parent_id"] == $parentId) { $kat["level"] = $level; $result[] = $kat; $result = getTree($cat, $kat["id"], ($level+1), $result); } } return $result; } ?>