Ako spočítať podkategórie,ktoré patria k hlavnej kategóriam
<?php
function get_menu($data, $parent_id = 0) {
static $i = 1;
$tab = str_repeat("\t\t", $i);
if (isset($data[$parent_id])) {
$html = "\n$tab<ul>";
$i++;
foreach ($data[$parent_id] as $v) {
$child = get_menu($data, $v->cat_id);
$html .= "\n\t$tab<li>";
$id = $v->cat_id;
$title = $v->cat_name;
$level= $v->level;
$j="jjj";
$html .= '<a href="'.$id.'">'.$title.'-'.$level.'-'.$j.'</a>';
// $html .= '<a href="'.$id.'">'.$title.'</a>';
if ($child) {
$i--;
$html .= $child;
$html .= "\n\t$tab";
}
$html .= '</li>';
}
$html .= "\n$tab</ul>";
return $html;
} else {
return false;
}
}
$result = mysql_query("SELECT * FROM categories ORDER BY cat_name asc");
$count=mysql_num_rows($result);
while ($row = mysql_fetch_object($result)) {
$data[$row->parent_id][] = $row;
}
$menu = get_menu($data);
?>
<div id="myjquerymenu" class="jquerycssmenu">
<?php echo $menu; ?>
</div>