$pdo = pdo_connect_mysql();
$mnu = '';
function Categories($cat)
{
global $pdo;
$sq = "SELECT * FROM categories WHERE parent = 0 ";
$stmt = $pdo->prepare($sq);
$stmt->execute();
$categories = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $categories;
}
$categories = Categories(0);
foreach($categories as $category) {
$cat = $category['cat'];
$parent = $category['parent'];
$label = $category['label'];
$mnu .= ' [*]' . $label . '';
Tree($cat);
$mnu .= '';
}
echo $mnu;
function Tree($cat)
{
global $mnu;
$categories = Categories($cat);
$count = count($categories);
if($count > 0) {
foreach($categories as $category) {
$mnu .= '
- ';
$cat = $category['cat'];
$parent = $category['parent'];
$label = $category['label'];
$mnu .= ' - ' . $label . '';
$categories = Categories($cat);
$count = count($categories);
if($count > 0) {
$mnu = substr($mnu, 0, -5);
Tree($cat);
}
}
$mnu .= '';
$mnu .= '
}
echo $mnu;
}
Подробнее здесь: https://stackoverflow.com/questions/788 ... do-and-not