您好,欢迎访问一九零五行业门户网

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

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; }

回复内容:
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; }

建议你下载ecshop的代码来看 说简单点他就是个树 当然像ecshop那样自己写代码用缩进拼出一个树来也是可以的
无限分类的实现一般情况下使用 parent_id / son_id 作为外键关系遍历一次就行了。分类太多性能跟不上的情况下换成预排序遍历树算法,实现上要复杂一些。
至于点击父类别显示所有子孙类别这种前端需求还是看看书好好学学吧。
ecstore 看看
其它类似信息

推荐信息