I am playing around with a code example i found here about \'tree menu\' and wanted to make this question.
function tree($id)
{
$query = \"SELECT `name`,`id`
I have a store with recursive inventory categories similar to what you're doing. Here's the code I wrote to present it as an unordered list (slightly modified for this example). Hope it helps!
/**
* Inventory Categories
*/
function inventoryCategories() {
$result = mysql_query("select * from store_inventorycategory");
$rows = array();
while ($row = mysql_fetch_array($result)) {
$p = $row['parent_category_id'];
$id = $row['id'];
$rows[$id] = array('id'=>$id, 'parent'=>$p, 'title'=>$row['title'], 'children'=>array());
}
foreach ($rows as $k=>&$v) {
if ($v['parent'] == $v['id']) continue;
$rows[$v['parent']]['children'][] = &$v;
}
array_splice($rows,1);
echo '';
recurseInventoryCategory($rows[0]);
echo '
';
}
/**
* display inventory category tree
*/
function recurseInventoryCategory ($o) {
echo "- {$o['title']}
";
foreach ($o['children'] as $v) {
recurseInventoryCategory($v);
}
echo "
";
}