Home > Backend Development > PHP Tutorial > About the code for implementing secondary loop reading in ThinkPHP

About the code for implementing secondary loop reading in ThinkPHP

不言
Release: 2023-03-30 21:14:02
Original
2088 people have browsed it

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);//映射值
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template