thinkphp 怎么实现循环取二级菜单
1个回答
2016-12-25 · 知道合伙人互联网行家
关注
展开全部
ThinkPHP实现二级循环读取的方法如下:
$Category = D('Category')->where('category_pid=0')->findAll();
//dump($Category);
if(!empty($Category)){ //判断一级是否为空
foreach($Category as $key=>$value){ //循环读取
$pid = $value['category_id'];//字段赋值
$Category[$key]['child'] = D('Category')->where("category_pid =$pid")->select();
//echo D('Category')->getLastSql(); //打印sql语句的写法
}
}
//dump($Category);
$this->assign('Category',$Category);//映射值
$Category = D('Category')->where('category_pid=0')->findAll();
//dump($Category);
if(!empty($Category)){ //判断一级是否为空
foreach($Category as $key=>$value){ //循环读取
$pid = $value['category_id'];//字段赋值
$Category[$key]['child'] = D('Category')->where("category_pid =$pid")->select();
//echo D('Category')->getLastSql(); //打印sql语句的写法
}
}
//dump($Category);
$this->assign('Category',$Category);//映射值
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询