Hey,
How do I implement multi-level dynamic navigation with php? Assuming my database would be like:
id name parent_id
----------------------------
1 page 0
2 sub1 1
3 sub2 1
4 sub12 2
I've tried many ways, but haven't found any 'good' methods/implementations so far.
Now I have:
$refs = array();
$list = array();
$pages = array();
foreach ($query->result_array() as $row)
{
$pages[] = $row;
}
foreach ($pages as $data)
{
$thisref = &$refs[ $data['page_id'] ];
$thisref['parent'] = $data['parent'];
$thisref['urlkey'] = $data['urlkey'];
$thisref['name'] = $data['name'];
$thisref['page_id'] = $data['page_id'];
if ($data['parent'] == 0) {
$list[ $data['page_id'] ] = &$thisref;
} else {
$refs[ $data['parent'] ]['children'][ $data['page_id'] ] = &$thisref;
}
}
print_r($list);
Thanks.