<?php
$sql = "select c.categories_id, cd.categories_name,c.parent_id from " .
TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
where c.categories_id=cd.categories_id and cd.language_id='" . (int)$_SESSION['languages_id'] . "' and c.categories_status='1'" .$order_by;
$categories = $db->Execute($sql);
$arr=array();
while (!$categories->EOF) {
$arr[]=array($categories->fields['categories_id'],$categories->fields['parent_id'],$categories->fields['categories_name']);
$categories->MoveNext();
}
function gg($parent_id,$level)
{
global $arr;
foreach($arr as $value_arr)
{
if($value_arr[1]==$parent_id)
{
echo str_repeat('=',$level).$value_arr[2].'<br />';
gg($value_arr[0],$level+10);
}
}
}
gg(0,1);
?>
第二种:
<?php
function display_children($parent, $level) {
global $db;
$categories_tab_query_son = "select c.categories_id, cd.categories_name,c.parent_id from " .
TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
where c.categories_id=cd.categories_id and cd.language_id='" . (int)$_SESSION['languages_id'] . "' and c.categories_status='1' and c.parent_id =$parent" .$order_by;
$categories_tab_son = $db->Execute($categories_tab_query_son);
while (!$categories_tab_son->EOF) {
$kk=$categories_tab_son->fields['categories_id'];
echo str_repeat('=',$level).$categories_tab_son->fields['categories_name']."<br>";
if(count($categories_tab_son->fields)!=0) display_children($kk, $level+10);
$categories_tab_son->MoveNext();
}
}
echo display_children(0,0);
?>