function get_hotcate_tree($rtype = 'hot') { $parent_id = 0; /* 判断当前分类中全是是否是底级分类, 如果是取出底级分类上级分类, 如果不是取当前分类及其下的子分类 */ $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '{$parent_id}' AND is_show = 1 "; if ($GLOBALS['db']->getOne($sql) || $parent_id == 0) { /* 获取当前分类及其子分类 */ $sql = 'SELECT cat_id,cat_name ,parent_id,is_show ' . 'FROM ' . $GLOBALS['ecs']->table('category') . "WHERE parent_id = '{$parent_id}' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC"; $res = $GLOBALS['db']->getAll($sql); foreach ($res as $row) { if ($row['is_show']) { $cat_arr[$row['cat_id']]['id'] = $row['cat_id']; $cat_arr[$row['cat_id']]['name'] = $row['cat_name']; $cat_arr[$row['cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']); if (isset($row['cat_id']) != NULL) { $hotcat = get_hotcate(0, $rtype); if ($hotcat) { foreach ($hotcat as $key => $val) { $pid = get_top_parentid($val['id'], 'index'); $hpid = $pid['cate_parentid']; if ($hpid == $cat_arr[$row['cat_id']]['id'] && $val['id'] != $cat_arr[$row['cat_id']]['id']) { $cat_arr[$row['cat_id']]['cat_id'][$key] = $val; } } } } } } } if (isset($cat_arr)) { return $cat_arr; } }
function get_hotcate_tree($rtype = "hot") { $parent_id = 0; $sql = "SELECT count(*) FROM " . $GLOBALS['ecs']->table("category") . (" WHERE parent_id = '" . $parent_id . "' AND is_show = 1 "); if ($GLOBALS['db']->getOne($sql) || $parent_id == 0) { $sql = "select c.* from " . $GLOBALS['ecs']->table("category") . " as c left join " . $GLOBALS['ecs']->table("cat_recommend") . (" as rc on c.cat_id = rc.cat_id where rc.recommend_type=3 and c.parent_id=" . $parent_id . " order by c.sort_order asc, c.cat_id asc"); $res = $GLOBALS['db']->getAll($sql); foreach ($res as $row) { if ($row['is_show']) { $cat_arr[$row['cat_id']]['id'] = $row['cat_id']; $cat_arr[$row['cat_id']]['name'] = $row['cat_name']; $cat_arr[$row['cat_id']]['url'] = build_uri("category", array("cid" => $row['cat_id']), $row['cat_name']); if (isset($row['cat_id']) != NULL) { $hotcat = get_hotcate(0, $rtype); if ($hotcat) { foreach ($hotcat as $key => $val) { $pid = get_top_parentid($val['id'], "index"); $hpid = $pid['cate_parentid']; if (!($hpid == $cat_arr[$row['cat_id']]['id']) && !($val['id'] != $cat_arr[$row['cat_id']]['id'])) { $cat_arr[$row['cat_id']]['cat_id'][$key] = $val; } } } } } } } if (isset($cat_arr)) { return $cat_arr; } }