ThinkPHP implements secondary loop reading method, thinkphp implements reading
The example in this article describes how ThinkPHP implements secondary loop reading. Share it with everyone for your reference. The specific implementation method is as follows:
Copy code The code is as follows:
$Category = D('Category')->where('category_pid=0')->findAll();
//dump($Category);
if(!empty($Category)){ //Judge whether level one is empty
foreach($Category as $key=>$value){ //Loop reading
$pid = $value['category_id'];//Field assignment
$Category[$key]['child'] = D('Category')->where("category_pid =$pid")->select();
//echo D('Category')->getLastSql(); //How to print the sql statement
}
}
//dump($Category);
$this->assign('Category',$Category);//Map value
I hope this article will be helpful to everyone’s ThinkPHP framework programming.
The way you write the array is too weird. Generally, no one would write data like this. We would write like this:
$data = array( 0 => array( 'id'=>1, 'cate_id'=>1, 'coo_name'=>111 ), 1 => array( 'id'=>2, 'cate_id'=>2, 'coo_name'=>222 )); Of course, your array can also be inserted in a loop: first convert the first id into an array, and then use foreach loop Insert
ThinkPHP template usage:
{$vo.id}
{$vo.name}
After getting this variable in the php page, $jgbh, $this->display('index'); This is the output of the page.
Just write the code in the html page.
{$vo.ip}
{$vo.khname}
ThinkPHP is a It is an open source framework. You can first download the user manual on the official website and look at the examples in order to learn it better and become familiar with its usage.
Hope it helps you
http://www.bkjia.com/PHPjc/904922.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/904922.htmlTechArticleThinkPHP implements two-level loop reading, thinkphp implements reading. This article describes the example of ThinkPHP implementing two-level loop reading. method of taking. Share it with everyone for your reference. The specific implementation methods are as follows...
Statement: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