Data nested loops in thinkphp and thinkphp nested loops. Data nested loop in thinkphp. the nested loop in thinkphp is used for thinkphp, and the second loop is associated with the outside. Thinkphp documentation provided on the official website: data nested loops in thinkphp and thinkphp nested loops
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:
{$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.
Background code:
$ 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:
{$vo.id}
{$sub.title}
Effect:
Thinkphp nested loop
{$ Sub}
</Volist>
</Volist>
How does one output data cyclically in thinkphp?
You need to use tag nesting. refer to ThinkPHP3.0 full development manual 8.21 tag nesting:
{$ Sub. name}
</Volist>
</Volist>
The nested loop in the loop is used for thinkphp, and the second loop is associated with the outside. Thinkphp official website documentation...