时间:2021-07-01 10:21:17 帮助过:9人阅读
本文实例讲述了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);//映射值
希望本文所述对大家的ThinkPHP框架程序设计有所帮助。