You are here: Re: Tree array « PHP Programming Language « IT news, forums, messages
Re: Tree array

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

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация