thinkphp the data in the nested Loop implementation method by classification, thinkphp nested
In this paper, the implementation method of nested loops of data in thinkphp is described. Share to everyone for your reference. The implementation method is as follows:
When doing thinkphp, it is necessary to use loops inside the loop, and the second loop is associated with the outside.
The documents given by the thinkphp website are:
Copy the Code code as follows:
{$sub. Name}
The table I want to use is: Classification table (table 1), Data Sheet (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 find out the classification table (table 1), and then the table 1 and table 2 are related to the query, and finally a two-dimensional array output
The background code is as follows:
Copy the Code code as follows: $m =m (' table 1 ');
$m 1=m (' Table 2 ');
$parent = $m->select ();
foreach ($parent as $n = = $val) {
$parent [$n] [' Voo ']= $m 1->where (' Table 2 and table 1 associated fields = '. $val [' Table 1id ']. ') ->select ();
}
$this->assign (' list ', $parent);
$this->display ();
The foreground output shows:
Copy the Code code as follows:
{$vo. ID}
{$sub. Title}
The effect is as follows:
It is hoped that this article is helpful to everyone's thinkphp program design.
thinkphp Nested Loops
{$sub}
</volist>
</volist>
thinkphp How to nest Loops
http://www.bkjia.com/PHPjc/903475.html www.bkjia.com true http://www.bkjia.com/PHPjc/903475.html techarticle thinkphp The data in the nested loop implementation method, thinkphp nested in this article describes the data in the thinkphp by the classification nested loop implementation method. Share to everyone for your reference. Concrete Reality ...