欢迎来到天天文库
浏览记录
ID:1481437
大小:36.00 KB
页数:6页
时间:2017-11-11
《ecshop2.7.0商品分类显示数量》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、ecshop2.7.0商品分类显示数量ecshop模板堂(ecmoban.com)修改includes/lib_goods.php,改写下两个函数。/***获得指定分类同级的所有分类以及该分类下的子分类**@accesspublic*@paraminteger$cat_id分类编号*@returnarray*/functionget_categories_tree($cat_id=0){if($cat_id>0){$sql='SELECTparent_idFROM'.$GLOBALS['ecs']->table('category')."WHEREca
2、t_id='$cat_id'";$parent_id=$GLOBALS['db']->getOne($sql);}else{$parent_id=0;}/*判断当前分类中全是是否是底级分类,如果是取出底级分类上级分类,如果不是取当前分类及其下的子分类*/$sql='SELECTcount(*)FROM'.$GLOBALS['ecs']->table('category')."WHEREparent_id='$parent_id'ANDis_show=1";if($GLOBALS['db']->getOne($sql)
3、
4、$parent_id==0){/
5、*获取当前分类及其子分类*/$sql='SELECTcat_id,cat_name,parent_id,is_show'.'FROM'.$GLOBALS['ecs']->table('category')."WHEREparent_id='$parent_id'ANDis_show=1ORDERBYsort_orderASC,cat_idASC";$res=$GLOBALS['db']->getAll($sql);$sql="SELECTcat_id,COUNT(*)ASgoods_num"."FROM".$GLOBALS['ecs']->table(
6、'goods')."ASg"."GROUPBYcat_id";$res2=$GLOBALS['db']->getAll($sql);$newres=array();foreach($res2AS$row){$newres[$row['cat_id']]=$row['goods_num'];}foreach($resAS$row){if($row['is_show']){$cat_arr[$row['cat_id']]['id']=$row['cat_id'];$cat_arr[$row['cat_id']]['num']=!empty($newres[
7、$row['cat_id']])?$newres[$row['cat_id']]:0;$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){$cat_arr[$row['cat_id']]['cat_id']=get_child_tree($row
8、['cat_id']);}}}}if(isset($cat_arr)){return$cat_arr;}}functionget_child_tree($tree_id=0){$three_arr=array();$sql='SELECTcount(*)FROM'.$GLOBALS['ecs']->table('category')."WHEREparent_id='$tree_id'ANDis_show=1";if($GLOBALS['db']->getOne($sql)
9、
10、$tree_id==0){$child_sql='SELECTcat_id,
11、cat_name,parent_id,is_show'.'FROM'.$GLOBALS['ecs']->table('category')."WHEREparent_id='$tree_id'ANDis_show=1ORDERBYsort_orderASC,cat_idASC";$res=$GLOBALS['db']->getAll($child_sql);$sql="SELECTcat_id,COUNT(*)ASgoods_num"."FROM".$GLOBALS['ecs']->table('goods')."ASg"."GROUPBYcat_id
12、";$res2=$GLOBALS['db']->getAll($sql);$newres=ar
此文档下载收益归作者所有