if($categoryId ==''){
$sql = "SELECT a.id, (select count(*) from files where category = a.id) AS cnt, a.parent, a.category FROM album a WHERE a.`group` = 'gallery' AND a.is_root = 1 ";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
echo "
" . $row["category"] . "
";
}
}else{
display_childrenSub("", 0);
}
function display_childrenSub($parent, $level) {
global $categoryId;
if ($parent == "") $sql = "SELECT a.id, (select count(*) from files where category = a.id) AS cnt, a.parent, a.category FROM album a WHERE a.`group` = 'gallery' AND a.id = '$categoryId' ";
else $sql = "SELECT a.id, (select count(*) from files where category = a.id) AS cnt, a.parent, a.category FROM album a WHERE a.`group` = 'gallery' AND a.parent = $parent ";
//echo $sql . " >> $level
";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
//echo str_repeat(' ',$level). $row['category'] . "
";
if ($level == 0) {
//echo "
" . $row["category"] . "
";
} else {
if ($row["cnt"] == 0)
echo "
" . str_repeat(' ', $level) . $row["category"] . "
";
else
echo "
" . str_repeat(' ', $level) . $row["category"] . "
";
}
display_childrenSub($row['id'], $level+1);
}
}
?>