自定义方法get_top_sub_category()
方法名:get_top_sub_category()
位 于:class category_tree
描 述:取出所有一级分类及相应二级分类列表
源 码:
function get_top_sub_category() {
$output_category_tree = array();
$num = 0;
global $db,$cPath,$cPath_array;
$top_category_query = "select c.categories_id, cd.categories_name, c.parent_id, c.categories_image
from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
where c.parent_id = 0
and c.categories_id = cd.categories_id
and cd.language_id='" . (int)$_SESSION['languages_id'] . "'
and c.categories_status= 1
order by sort_order, cd.categories_name";
$top_category = $db->Execute($top_category_query);
if($top_category->RecordCount()>0) {
while (!$top_category->EOF) {
$output_category_tree[$num]['name'] = $top_category->fields['categories_name'];
$output_category_tree[$num]['href'] = zen_href_link(FILENAME_DEFAULT, 'cPath='.(int)$top_category->fields['categories_id']);
$output_category_tree[$num]['type'] = 'top';
$num++;
$sub_category_query = "select c.categories_id, cd.categories_name, c.parent_id, c.categories_image
from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
where c.parent_id = " . (int)$top_category->fields['categories_id'] . "
and c.categories_id = cd.categories_id
and cd.language_id=" . (int)$_SESSION['languages_id'] . "
and c.categories_status= 1
order by sort_order, cd.categories_name";
$sub_category = $db->Execute($sub_category_query);
if($sub_category->RecordCount()>0) {
while (!$sub_category->EOF) {
$output_category_tree[$num]['name'] = $sub_category->fields['categories_name'];
$output_category_tree[$num]['href'] =zen_href_link(FILENAME_DEFAULT, 'cPath='.$top_category->fields['categories_id'].'_'.$sub_category->fields['categories_id']);
$output_category_tree[$num]['type'] = 'sub';
$num++;
$sub_category->MoveNext();
}
}
$top_category->MoveNext();
}
}
return $output_category_tree;
}

浙公网安备 33010602011771号