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是一个开源的框架,你可以先在官网上下载个使用手册,看看里面的例子,才能更好的学习它和熟悉它的用法。
希望能帮助到你

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download
The most popular open source editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version
Visual web development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment
