RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
无线分类新写法,是不是很吊@!

 * @license
 * @Copyright (c) 2009-2016 http://www.lvmaque.com All rights reserved.
 */
class Model_Shop_Class{

    protected  $_table_name = 'shop_goods_class';
    protected  $_primary_key= 'gc_id';

    /**
     * ***************************************************************
     * 获得排列好的分类信息 2016年04月26日18:43:22
     * ***************************************************************
     * @param
     * @return void
     * @author 王迪<2880707519@qq.com>
     * @license
     * @Copyright (c) 2009-2016 http://www.lvmaque.com All rights reserved.
     */
    public static function getList(){
        $parent_0   =  "select gc_id,gc_parent_id from sline_shop_goods_class where gc_parent_id=0";
        $list       =  DB::query(Kohana_Database::SELECT,$parent_0)->execute()->as_array();
        $parentArray=array();
        $parentArray[0]=$list;
        $parentArray['findIds']=$list;

        self::getChild($parentArray);
        return $parentArray;
    }


    //查找子集
    public static function getChild(&$parent){
        //id的数组
        $idArray = Kohana_Util::only_array($parent['findIds'],'gc_id');

        //id连接城字符串
        $idString = implode(',',$idArray);

        $child = "select gc_id,gc_parent_id from sline_shop_goods_class where gc_parent_id in ({$idString})";
        $childRes = DB::query(Kohana_Database::SELECT,$child)->execute()->as_array();

        if(count($childRes)<1){
            return;
        }

        $parent['findIds']=$childRes;

        //按parent_id把数组存储起来
        foreach($childRes as $v){
            $parent[$v['gc_parent_id']][]=$v;
        }

        self::getChild($parent);
    }
}

这么做查数据库的效率会比较高,是一层一层的往下查的

福海网站建设公司创新互联,福海网站设计制作,有大型网站制作公司丰富经验。已为福海上千家提供企业网站建设服务。企业网站搭建\外贸网站制作要多少钱,请找那个售后服务好的福海做网站的公司定做!

找子集的时候就从parent_id等于零开始查找,

然后循环0键值对应的数组,

再找里面的parent_id对应的键值是否存在,如果存在就把里面的继续遍历,如果不存在就结束递归!

O(∩_∩)O哈哈哈~!,我是不是很6,绝对原创,亲!转载只要998!


标题名称:无线分类新写法,是不是很吊@!
网页路径:http://sczitong.cn/article/iispei.html