global $link;
if($count == 0){
echo '
- ';
} else {
echo '';
}
foreach ($parent as $id => $cat) {
if($cat['parent_id'] == '0'){
echo ' -
' . $cat['category'] . '';
} else {
$indent = str_repeat(' ', $depth * 3);
echo '' . $indent . '
' . $cat['category'] . '';
}
if (isset($link[$id])) {
make_list($link[$id], $count+1, $depth+1);
}
echo '';
}
echo '
}
$dbc = mysqli_query($mysqli,"SELECT * FROM categories ORDER BY parent_id, category ASC");
if (!$dbc) {
print mysqli_error();
}
$link = array();
while (list($id, $parent_id, $category, $depth) = mysqli_fetch_array($dbc)) {
$link[$parent_id][$id] = array('parent_id' => $parent_id, 'id' => $id, 'category' => $category, 'depth' => $depth);
}
make_list($link[0], $depth+1);
Подробнее здесь: https://stackoverflow.com/questions/352 ... nt-problem
Мобильная версия