A _php example of the implementation of data nested loops by classification in thinkphp

Source: Internet
Author: User

In this paper, we describe the method of data nesting by classification in thinkphp. Share to everyone for your reference. The implementation methods are as follows:

When doing thinkphp, you use loops inside the loop, and the second loop is associated with the outside.
Thinkphp's official website gives the following documents:

Copy Code code as follows:
<volist name= "list" id= "Vo" >
<volist name= "vo[' Sub '" "Id=" sub ">
{$sub. Name}
</volist>
</volist>

The table I want to use here is: Category table (table 1), Datasheet (table 2)
The effect you want to implement 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), and then table 1 and table 2 associated with the query, and finally the two-dimensional array of output

The background code is as follows:

Copy 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 (' The field associated with table 2 and 1 = '. $val [' Table 1id ']. ') ->select ();
}
$this->assign (' list ', $parent);
$this->display ();

The foreground output shows:

Copy Code code as follows:
<volist name= "list" id= "Vo" >
<li><b>{$vo .id}</b></li>
<volist name= "vo[' Voo ']" id= "sub" >
<li>{$sub .title}</li>
</volist>
</volist>

The effect is shown in the following illustration:

I hope this article will help you with the thinkphp program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.