php分类查询,ThinkPHP分类相关查询(获取所有子分类,获取父分类,下一级分类等)...

//获取指定分类的所有子分类ID号    function getAllChildcateIds($categoryID)    {        //初始化ID数组        $array[] = $categoryID;        do        {            $ids = '';            $where['pid'] = array('in',$categoryID);            $cate = M('cate')->where($where)->select();            foreach ($cate as $k=>$v)            {                $array[] = $v['id'];                $ids .= ',' . $v['id'];            }            $ids = substr($ids, 1, strlen($ids));            $categoryID = $ids;        }        while (!empty($cate));        $ids = implode(',', $array);        return $ids;    //  返回字符串        //return $array //返回数组    }      //获取指定分类所有父ID号    function getAllFcateIds($categoryID)    {        //初始化ID数组        $array[] = $categoryID;                 do        {            $ids = '';            $where['id'] = array('in',$categoryID);            $cate = M('cate')->where($where)->select();            echo M('cate')->_sql();            foreach ($cate as $v)            {                $array[] = $v['pid'];                $ids .= ',' . $v['pid'];            }            $ids = substr($ids, 1, strlen($ids));            $categoryID = $ids;        }        while (!empty($cate));         $ids = implode(',', $array);         return $ids;   //  返回字符串        //return $array //返回数组    }        //获取指定分类的所有子分类 键为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 //返回数组    }]]>

原创文章,作者:键盘游走者,如若转载,请注明出处:http://www.708034.com/2017/04/thinkphp%e5%88%86%e7%b1%bb%e7%9b%b8%e5%85%b3%e6%9f%a5%e8%af%a2%e8%8e%b7%e5%8f%96%e6%89%80%e6%9c%89%e5%ad%90%e5%88%86%e7%b1%bb%ef%bc%8c%e8%8e%b7%e5%8f%96%e7%88%b6%e5%88%86%e7%b1%bb%ef%bc%8c%e4%b8%8b/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值