When doing thinkphp, you need to use nested loops inside loops, and the second loop is related to the outside of.
The document provided by thinkphp official website is:
<volist name=<span>"</span><span>list</span><span>"</span> id=<span>"</span><span>vo</span><span>"</span>> <volist name=<span>"</span><span>vo['sub']</span><span>"</span> id=<span>"</span><span>sub</span><span>"</span>><span> {$sub.name} </span></volist> </volist>
The tables I want to use here are: classification table (Table 1), data table (Table 2)
The effect to be achieved is:
<表1_1> <表2_1/> <表2_2> </表1_1> <表1_2> <表2_3/> <表2_4> </表1_2>
In fact, the principle is to first find the classification table (Table 1), then query Table 1 and Table 2, and finally output it in the form of a two-dimensional array
Backend code:
$m=M(<span>'</span><span>表1</span><span>'</span><span>); $m1</span>=M(<span>'</span><span>表2</span><span>'</span><span>); $parent</span>=$m-><span>select</span><span>(); </span><span>foreach</span>($parent <span>as</span> $n=><span> $val){ $parent[$n][</span><span>'</span><span>voo</span><span>'</span>]=$m1-><span>where</span>(<span>'</span><span>表2里和表1相关联的字段=</span><span>'</span>.$val[<span>'</span><span>表1id</span><span>'</span>].<span>''</span>)-><span>select</span><span>(); } $</span><span>this</span>->assign(<span>'</span><span>list</span><span>'</span><span>,$parent); $</span><span>this</span>->display();
Foreground output display:
<volist name=<span>"</span><span>list</span><span>"</span> id=<span>"</span><span>vo</span><span>"</span>> <li><b>{$vo.id}</b></li> <volist name=<span>"</span><span>vo['voo']</span><span>"</span> id=<span>"</span><span>sub</span><span>"</span>> <li>{$sub.title}</li> </volist> </volist>
The effect is:
{$sub}
You need to use tag nesting, please refer to ThinkPHP3.0 Complete Development Manual 8.21 Tag nesting:
{$sub.name}