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:
<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.
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:
<volist name="list" id="vo"> <li><b>{$vo.id}</b></li> <volist name="vo['voo']" id="sub"> <li>{$sub.title}</li> </volist> </volist>
Effect:
Thinkphp nested loop
<Volist name = "article" id = "vo">
<Volist name = "vo ['Post _ tag']" id = "sub">
{$ 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:
<Volist name = "list" id = "vo">
<Volist name = "vo ['sub']" id = "sub">
{$ Sub. name}
</Volist>
</Volist>