Data nested loops in thinkphp and thinkphp nested loops

Source: Internet
Author: User

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>

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.