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

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

WBOY
Release: 2016-06-13 09:22:24
Original
1159 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框架程序设计有所帮助。

THINKPHP中怎进行循环插入多条数据

你这数组写的也太那个了吧,一般谁都不会把数据写成这样的。我们会这样写:
$data = array( 0 => array( 'id'=>1, 'cate_id'=>1, 'coo_name'=>111 ), 1 => array( 'id'=>2, 'cate_id'=>2, 'coo_name'=>222 ));当然你这个数组也可以循环插入的:先把第一个id转换为数组,然后用foreach循环插入

 

foreach双重循环怎在ThinkPHP模板中输出

ThinkPHP模板用法:

{$vo.id}
{$vo.name}

在php页面得到这个变量后$jgbh,$this->display('index');这是页面的输出,
在html页面里写代码就行。

{$vo.ip}
{$vo.khname}

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!