Answer the question
In order to leave comments, you need to log in
How to store categories with subcategories in the database?
$list_category = [
"автоматика",
"архитектура",
"бетонные работы",
"бурение скважин",
"двери"=>[
"деревянные"=>[
"изготовление",
"установка",
"реставрация",
],
"металлические"=>[
"изготовление",
"установка",
"реставрация",
],
"пластиковые"=>[
"изготовление",
"установка",
"реставрация",
],
],
"земляные работы",
"камин",
"кладка"=>[
"каменная",
"кирпичная",
],
];
<?php
require_once "../config/function.php";
$sql = 'SELECT * FROM categories';
$lastChar = null;
foreach ($conndb->query($sql) as $row):
if ($lastChar !== ($currentChar = mb_convert_case(mb_substr($row['category_name'], 0, 1), CASE_UPPER))):
$lastChar = $currentChar;
?>
<h1 class="bukva" id="bukva_<? echo replaceSymbolRuToLat($lastChar); ?>"><? echo mb_convert_case($lastChar, CASE_LOWER); ?></h1>
<?php
endif;
?>
<a href="http://localhost/menu_general/masters_page/masters/masters.php">
<div class="kategoriya">
<div class="kolichestvo">0</div>
<?php echo $row['category_name'] . "\t"; ?>
</div>
</a>
<?php
endforeach;
?>
Answer the question
In order to leave comments, you need to log in
Educational program on storing tree-like (hierarchical) data structures in the database
https://gist.github.com/codedokode/10539720
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question