获取指定分类所有父ID号
$categoryList = Db::name('goods_category')
->where('status',1)
->field('gc_id,gc_name,parent_id')
->select();
if(!empty($categoryList))
{
while($catId != 0){
foreach($categoryList as $item){
if($item['gc_id']==$catId){
$tree[]=$item;
$catId=$item['parent_id'];
break;
}
}
}
}
return array_reverse($tree); //数组倒序排列
//获取指定分类的所有子分类ID
function getAllChildCateIds($categoryID)
{
//初始化ID数组
$array[] = $categoryID;
do
{
$ids = '';
$catWhere['parent_id'] = array('IN',$categoryID);
$cate = Db::name('goods_category')->where($catWhere)->field('gc_id')->select();
foreach ($cate as $k=>$v)
{
$array[] = $v['gc_id'];
$ids .= ',' . $v['gc_id'];
}
$ids = substr($ids, 1, strlen($ids));
$categoryID = $ids;
}
while (!empty($cate));
$ids = implode(',', $array);
return $ids;
}
//获取指定分类的所有子分类 键为ID,值为分类名
function getCateKv($categoryID)
{
//初始化ID数组,赋值当前分类
$array[] = M('cate')->where("id={$categoryID}")->getField("cateName");
do
{
$ids = '';
$where['pid'] = array('in',$categoryID);
$cate = M('cate')->where($where)->select();
echo M('cate')->_sql();
foreach ($cate as $k=>$v)
{
$array[$v['id']] = $v['cateName'];
$ids .= ',' . $v['id'];
}
$ids = substr($ids, 1, strlen($ids));
$categoryID = $ids;
}
while (!empty($cate));
$ids = implode(',', $array);
//return $ids; // 返回字符串
return $array //返回数组
}