function printSQLResultTree($result, $colDefn = null) { if ($colDefn == null) { $colDefn = array("groupCol" => "category", "titleCol" => "title"); } $groupCol = $colDefn["groupCol"]; $titleCol = $colDefn["titleCol"]; if (isset($colDefn["categoryCol"])) { $categoryCol = $colDefn["categoryCol"]; } else { $categoryCol = ""; } if ($result) { $out = array(); $cnt = 0; while ($row = _db()->fetchData($result)) { if (strlen($row[$groupCol]) <= 0) { $row[$groupCol] = ""; } else { $row[$groupCol] = "" . $row[$groupCol]; } $record = array("data" => $row); if (strpos($row[$groupCol], "/") >= 1) { $gs = $row[$groupCol]; if (isset($row[$categoryCol]) && strlen($row[$categoryCol]) > 0) { $gs .= "/" . $row[$categoryCol]; } $gs = str_replace("//", "/", $gs); $r = explode("/", $gs); array_push($r, $row[$titleCol]); $arr = $record; $r1 = array_reverse($r); foreach ($r1 as $a) { $arr = array($a => $arr); } $out[$cnt] = $arr; } else { if (strlen($row[$groupCol]) <= 0) { if (!isset($row[$categoryCol]) || strlen($row[$categoryCol]) <= 0) { $out[$cnt][$row[$titleCol]] = $record; } else { $out[$cnt][$row[$categoryCol]][$row[$titleCol]] = $record; } } else { if (!isset($row[$categoryCol]) || strlen($row[$categoryCol]) <= 0) { $out[$cnt][$row[$groupCol]][$row[$titleCol]] = $record; } else { $out[$cnt][$row[$groupCol]][$row[$categoryCol]][$row[$titleCol]] = $record; } } } $cnt++; } _db()->freeResult($result); $treeArray = array(); foreach ($out as $a => $b) { $treeArray = array_merge_recursive($treeArray, $b); } /*$atl=new ArrayToList(); $atl->colDefns($colDefn); $atl->listTags($format); $s=$atl->getTree($treeArray,"data"); $s=substr($s,4,strlen($s)-9); return $s;*/ return printTreeList($treeArray); } return ""; }
function printTreeList($treeArray) { if (count($treeArray) <= 0) { return ""; } $s = ""; foreach ($treeArray as $a => $b) { $data = $b['data']; unset($b['data']); if (count($b) > 0) { $s .= "<li>"; $s .= "<h3 rel='{$data['id']}'>{$a}</h3>"; $s .= "<ul>"; $s .= printTreeList($b); $s .= "</ul>"; $s .= "</li>"; } else { $s .= "<li><a rel='{$data['id']}'>{$a}</a></li>"; } } return $s; }