ThinkPHP implements the second-level cyclic read method, and thinkphp implements read

Source: Internet
Author: User
Tags echo d

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
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.