Implementation of nested loops of data by category in Thinkphp and nested in thinkphp

Source: Internet
Author: User

Implementation of nested loops of data by category in Thinkphp and nested in thinkphp

This article describes how to implement a nested loop of data in Thinkphp by category. Share it with you for your reference. The specific implementation method is as follows:

During thinkphp, nested loops are used in the loop, and the second loop is associated with the outside.
The thinkphp official website provides the following documents:

Copy codeThe Code is as follows: <volist name = "list" id = "vo">
<Volist name = "vo ['sub']" id = "sub">
{$ Sub. name}
</Volist>
</Volist>

The tables I want to use here are: classification table (table 1) and data table (table 2)
The effect to be achieved is:

<Table 1_1>
<Table 2_1/>
<Table 2_2>
</Table 1_1>
<Table 1_2>
<Table 2_3/>
<Table 2_4>
</Table 1_2>

In fact, the principle is to first identify the classification table (table 1), then associate Table 1 and Table 2 for query, and finally output the data in a two-dimensional array.

The background code is as follows:

Copy codeThe Code is as follows: $ m = M ('table 1 ');
$ M1 = M ('table 2 ');

$ Parent = $ m-> select ();
Foreach ($ parent as $ n => $ val ){
$ Parent [$ n] ['voo'] = $ m1-> where ('field associated with table 1 in Table 2 = '. $ val ['table 1id']. '')-> select ();
}
$ This-> assign ('LIST', $ parent );
$ This-> display ();
Foreground output:

Copy codeThe Code is as follows: <volist name = "list" id = "vo">
<Li> <B >{$ vo. id} </B> </li>
<Volist name = "vo ['voo']" id = "sub">
<Li >{$ sub. title} </li>
</Volist>
</Volist>
Shows the effect:

I hope this article will help you with ThinkPHP programming.


Thinkphp nested loop

<Volist name = "article" id = "vo">
<Volist name = "vo ['Post _ tag']" id = "sub">
{$ Sub}
</Volist>
</Volist>

How to nest a loop in thinkphp

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.