12-16-2007, 09:22 PM
[eluser]zerone[/eluser]
This can - and should - be acomplished with one query.
The trick is to organize your items on an array.
Iterate all your menu entries and each one will go to a bag:
Then just implement with your's friend function or create your own.
The function is first called with with the bag with empty parent_id;
Then recursive_tree is only responsible for printing each item of $items childs:
There are prettier ways to do this, even by OOP which would be a lot more customizable.
This can - and should - be acomplished with one query.
The trick is to organize your items on an array.
Iterate all your menu entries and each one will go to a bag:
Code:
$all_items[ $row['parent_id'] ][] = $row;
Then just implement with your's friend function or create your own.
The function is first called with with the bag with empty parent_id;
Code:
echo recursive_tree($all_items['']);
Then recursive_tree is only responsible for printing each item of $items childs:
Code:
function recursive_tree($items)
{
global $all_item;
echo '<ul>';
foreach ($items as $item)
{
echo "<li>{$item['name']}</li>";
recursive_tree($all_items[ $item['id'] ]);
}
echo '</ul>';
}
There are prettier ways to do this, even by OOP which would be a lot more customizable.