$razd_menu = $db->query("SELECT *, menu.id FROM `menu` LEFT JOIN `category` ON menu.id = category.num_cat-1 ORDER BY menu.id, category.id");
$mas = array();
foreach($razd_menu as $row){
if(!empty($row['lat_name_cat'])){
$mas[$row['name_razdel']]= $mas[$row['name_razdel']]+1;
}
}