如何实现无限分类 点击一个商品分类 显示本分类以及所有子分类的商品?

WBOY
Release: 2016-06-06 20:26:47
Original
1776 people have browsed it

如何实现无限分类 点击一个商品分类 显示本分类以及所有子分类的商品?

<code>            function isHaveChildCategory($cid){
                $m=M('goods_category');
                $con['goodscategory_pid']=$cid;
                $result=$m->where($con)->getField('goodscategory_id',true);




                foreach($result as $key=>$value){
                   isHaveChildCategory($value);

                }




                return $result;

            }</code>
Copy after login
Copy after login

回复内容:

如何实现无限分类 点击一个商品分类 显示本分类以及所有子分类的商品?

<code>            function isHaveChildCategory($cid){
                $m=M('goods_category');
                $con['goodscategory_pid']=$cid;
                $result=$m->where($con)->getField('goodscategory_id',true);




                foreach($result as $key=>$value){
                   isHaveChildCategory($value);

                }




                return $result;

            }</code>
Copy after login
Copy after login

建议你下载ecshop的代码来看 说简单点他就是个树 当然像ecshop那样自己写代码用缩进拼出一个树来也是可以的

无限分类的实现一般情况下使用 parent_id / son_id 作为外键关系遍历一次就行了。分类太多性能跟不上的情况下换成预排序遍历树算法,实现上要复杂一些。
至于点击父类别显示所有子孙类别这种前端需求还是看看书好好学学吧。

ecstore 看看

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template