Home  >  Article  >  Backend Development  >  ThinkPHP实现二级循环读取的方法_PHP

ThinkPHP实现二级循环读取的方法_PHP

WBOY
WBOYOriginal
2016-05-31 19:28:37993browse

ThinkPHP

本文实例讲述了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框架程序设计有所帮助。

Statement:
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