Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-06-06 20:17:59
Original
1845 people have browsed it

这篇文章主要介绍了ThinkPHP实现二级循环读取的方法,是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框架程序设计有所帮助。

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!