ciao,
sono alle prese con la modifica di uno script per creare un menu di navigazione verticale, in cui mettere come 1a voce di menu, le categorie e come 2a voce, le sub-categorie

Nel DB mysql la tabella per categorie e sub-categorie purtroppo è una sola e non posso cambiare il sistema
come da immagine:



lo script funziona regolarmente, solo che vorrei modificare il modo di visualizzare i dati nel menu di navigazione

la classe php:
Codice PHP:
function formatCategories($categories$parentId

// $navCat stores all children categories 
// of $parentId 
$navCat = array(); 
// expand only the categories with the same parent id 
// all other remain compact 
$ids = array(); 
foreach (
$categories as $category

if (
$category['cat_parent_id'] == $parentId
$navCat[] = $category; } 
// save the ids for later use 
$ids[$category['cat_id']] = $category

$tempParentId $parentId
// keep looping until we found the 
// category where the parent id is 0 
while ($tempParentId != 0

$parent = array($ids[$tempParentId]); 
$currentId $parent[0]['cat_id']; 
// get all categories on the same level as the parent 
$tempParentId $ids[$tempParentId]['cat_parent_id']; 
foreach (
$categories as $category

// found one category on the same level as parent 
// put in $parent if it's not already in it 
if ($category['cat_parent_id'] == $tempParentId && !in_array($category$parent)) 
$parent[] = $category; } 

// sort the category alphabetically 
array_multisort($parent); 
// merge parent and child 
$n count($parent); 
$navCat2 = array(); 
for (
$i 0$i $n$i++) 
$navCat2[] = $parent[$i]; 
if (
$parent[$i]['cat_id'] == $currentId
$navCat2 array_merge($navCat2$navCat); 

$navCat $navCat2

return 
$navCat

e nella home i la classe viene richiamata nel seguente modo:
Codice PHP:
// get all categories 
$categories = fetchCategories(); 
// format the categories for display 
$categories = formatCategories($categories, $catId); 
foreach ($categories as $category) 

extract($category); 
// now we have $cat_id, $cat_parent_id, $cat_name 
$level = ($cat_parent_id == 0) ? 1 : 2; 
$url = $_SERVER['PHP_SELF'] . "?c=$cat_id"; 
// for second level categories we print extra spaces to give 
// indentation look 
if ($level == 2) 

echo"<ul>"; 
 } 
?>
  <li class="sub">[url="<?php echo $url?>"]<?php echo $cat_name?>[/url] 
 <?php
}
?>
Cosa voglio che faccia il menu?


<ul id="menu">

<li class="sub">Cimatizzazione
<li class="sub">Riscaldamento
<ul>
<li class="sub">Stufe a legna
<li class="sub">Stufe a pellet[/list]
<li class="sub">Energie alternative[/list]

Cosa che non riesco ad ottenere...

Spero di essere stato chiaro
Grazie per l'aiuto