|
Posted by Rik on 05/30/06 12:39
leonardo.calado@gmail.com wrote:
> In the system information is stored to make a breadcrumbs site
> functionality, page_path stores de location in breadcrumbs from page.
> For example: page_id 9 "Contact" have 2 levels of depht to home. It's
> make the following breadcrumb Home > Products > Contact
Which is still possible, using Oil's table.
I'm making a trail here, allthough with the build of the array this is
totally unnecessary:
function create_tree($parent=null, $depth=0, $trail='x' ){
$return = array();
$result = mysql_query("SELECT page_id, page_order, page_title
FROM table
WHERE page_parent='$parent'
ORDER BY page_order");
if(mysql_num_rows($result) > 0){
while($row = mysql_fetch_assoc($result)){
$return[$row['page_id']] = $row;
$return[$row['page_id']]['depth'] = $depth;
$return[$row['page_id']]['trail'] = $trail;
$childs =
create_tree($row['page_id'],$depth+1,$trail.'.'.$row['page_id']);
if(!empty($childs)){
$return[$row['page_id']]['childs'] = $childs
}
}
}
return $return;
}
$tree = create_tree();
function create_html_list($array){
if(!is_array($array)) return '';
$return = '<ul>';
foreach($array as $row){
$return .="<li>{$row['page_title']}";
if(isset($row['childs'])&&is_array($row['childs']){
$return .= create_html_list($row['childs']);
}
$return .='</li>';
}
$return = '</ul>';
return $return;
}
echo create_html_list($tree);
Ν haven't tested the code, so maybe some debugging is in order.
Grtz,
--
Rik Wasmus
[Back to original message]
|