本文實例講述了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框架程序設計有所幫助。