On the Internet, I found: the MySQL category tree and the PHP recursive function. I did the same, but I have the entire list in a row vertically.
rfr How to customize styles for this script? And to make an accordion for him to click on the parent list, the child opened. And close the previous open child lists.
// подключаемся к базе данных // делаем выборку из таблицы категорий $result = mysql_query ("SELECT `id`, `parent_id`, `name` FROM `category`"); $cats = array(); // тут будет наш массив с категориями каталога // в цикле формируем нужный нам массив while($cat = mysql_fetch_assoc($result)) $cats[$cat['parent_id']][] = $cat; // далее наша главная, рекурсивная функция, которая сформирует дерево категорий function create_tree ($cats,$parent_id){ if(is_array($cats) and isset($cats[$parent_id])){ $tree = '<ul>'; foreach($cats[$parent_id] as $cat){ $tree .= "<li><a href='view_cat.php?cat=".$cat['id']."'>".$cat['name']."</a>"; $tree .= create_tree ($cats,$cat['id']); $tree .= '</li>'; } $tree .= '</ul>'; } else return null; return $tree; } // вызываем функцию и строим дерево echo create_tree ($cats, 0); 
