Home >Backend Development >PHP Tutorial >About the code for implementing secondary loop reading in ThinkPHP
This article mainly introduces the method of ThinkPHP to implement two-level loop reading, which is a very common technique in ThinkPHP's array-based database operations. Friends in need can refer to it
The examples in this article describe the implementation of ThinkPHP Second-level loop reading method. Share it with everyone for your reference. The specific implementation method is as follows:
$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);//映射值
The above is the entire content of this article. I hope it will be helpful to everyone’s learning. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
thinkPHP implements the function of linkage menu
thinkPHP implements the example of the three-level linkage function of provinces and municipalities
The above is the detailed content of About the code for implementing secondary loop reading in ThinkPHP. For more information, please follow other related articles on the PHP Chinese website!