In Thinkphp, data is nested by classification and nested by thinkphp. In Thinkphp, data is nested by category. thinkphp nesting this article describes how to implement data nested by category in Thinkphp. Share it with you for your reference. The implementation method of data nested by category in Thinkphp is as follows:
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:
The code is as follows:
{$ Sub. name}
The tables I want to use here are: Classification Table (Table 1) and data table (Table 2)
The effect to be achieved is:
<表1_1>
<表2_1 />
<表2_2>
<表1_2>
<表2_3 />
<表2_4>
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:
The 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:
The code is as follows:
{$ Vo. id}
{$ Sub. title}
Shows the effect:
I hope this article will help you with ThinkPHP programming.
Thinkphp nested loop
{$ Sub}
</Volist>
</Volist>
How to nest a loop in thinkphp
Examples in this article describes how to implement a nested loop of data in Thinkphp by category. Share it with you for your reference. Details...