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框架程序设计有所帮助。
你这数组写的也太那个了吧,一般谁都不会把数据写成这样的。我们会这样写:
$data = array( 0 => array( 'id'=>1, 'cate_id'=>1, 'coo_name'=>111 ), 1 => array( 'id'=>2, 'cate_id'=>2, 'coo_name'=>222 ));当然你这个数组也可以循环插入的:先把第一个id转换为数组,然后用foreach循环插入
ThinkPHP模板用法:
{$vo.id}
{$vo.name}
在php页面得到这个变量后$jgbh,$this->display('index');这是页面的输出,
在html页面里写代码就行。
{$vo.ip}
{$vo.khname}
ThinkPHP是一个开源的框架,你可以先在官网上下载个使用手册,看看里面的例子,才能更好的学习它和熟悉它的用法。
希望能帮助到你

Heiße KI -Werkzeuge

Undresser.AI Undress
KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover
Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool
Ausziehbilder kostenlos

Clothoff.io
KI-Kleiderentferner

AI Hentai Generator
Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

Heiße Werkzeuge

Herunterladen der Mac-Version des Atom-Editors
Der beliebteste Open-Source-Editor

PHPStorm Mac-Version
Das neueste (2018.2.1) professionelle, integrierte PHP-Entwicklungstool

Senden Sie Studio 13.0.1
Leistungsstarke integrierte PHP-Entwicklungsumgebung

WebStorm-Mac-Version
Nützliche JavaScript-Entwicklungstools

SublimeText3 Mac-Version
Codebearbeitungssoftware auf Gottesniveau (SublimeText3)