Heim  >  Artikel  >  Backend-Entwicklung  >  shopNC分类,递归方式查询层级显示

shopNC分类,递归方式查询层级显示

WBOY
WBOYOriginal
2016-08-08 09:19:31937Durchsuche

1、先贴图:
数据库分类表

2、要求,依据分类表,分层级显示,如图:
展示效果图

3、实现,贴代码如下:

//分类列表查询

<code>$tmp_list = $model_class->getTreeClassList(3);//所有列表
    if (is_array($tmp_list)){
        foreach ($tmp_list as $k => $v){
            $num = $model_class->recursive($v['tax_parent_id']);//此处需要用到递归查询方法
            $tmp_list[$k]['tax_name'] = str_repeat(" —",$num).$v['tax_name'];
        }
    }
</code>

//递归查询
//@param int $tax_parent_id 父级ID

//@param int $num

<code>public function recursive($tax_parent_id, $num = 0){
    $parent = $this->getGoodsClassinfo(array('tax_id'=>$tax_parent_id,'tax_parent_id'));
    if($parent == true){
        $num++;
        $num = $this->digui($parent['tax_parent_id'],$num); 
    }
    return $num;
}
</code>

4、完成

版权声明:本文为博主原创文章,转载请通知博主邮箱:519585292@qq.com。

以上就介绍了shopNC分类,递归方式查询层级显示,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:15 PHP 全局变量 - 超全局变量Nächster Artikel:Nginx 定时器