ThinkPHP implements the second-level cyclic read method, and thinkphp implements read
This example describes how ThinkPHP implements second-level cyclic reading. Share it with you for your reference. The specific implementation method is as follows:
Copy codeThe Code is as follows:
$ Category = D ('category ')-> where ('category _ pid = 0')-> findAll ();
// Dump ($ Category );
If (! Empty ($ Category) {// determines whether a level 1 is empty
Foreach ($ Category as $ key => $ value) {// read cyclically
$ Pid = $ value ['category _ id']; // field value assignment
$ Category [$ key] ['child '] = D ('category')-> where ("category_pid = $ pid")-> select ();
// Echo D ('category ')-> getLastSql (); // print the SQL statement syntax
}
}
// Dump ($ Category );
$ This-> assign ('category ', $ Category); // ing Value
I hope this article will help you with ThinkPHP framework programming.
How to insert multiple data entries cyclically in THINKPHP
You have written this array too well. Generally, no one will write the data like this. We will write as follows:
$ Data = array (0 => array ('id' => 1, 'cate _ id' => 1, 'coo _ name' => 111 ), 1 => array ('id' => 2, 'cate _ id' => 2, 'coo _ name' => 222 )); of course, you can insert this array cyclically: first convert the first id to an array, and then insert it cyclically using foreach.
How to output foreach dual loops in the ThinkPHP Template
ThinkPHP template usage:
<Foreach name = "list" item = "vo">
{$ Vo. id}
{$ Vo. name}
</Foreach>
After getting this variable on the php page $ jgbh, $ this-> display ('index'); this is the output of the page,
Write the code on the html page.
<Foreach name = "jgbh" item = "vo">
{$ Vo. ip}
{$ Vo. khname}
</Foreach>
ThinkPHP is an open-source framework. You can download a user manual from the official website and take a look at the examples to better learn ThinkPHP and familiarize yourself with its usage.
Hope to help you