Data nested loop in thinkphp and thinkphp nested loop _ PHP Tutorial

Source: Internet
Author: User
Data nested loops in thinkphp and thinkphp nested loops. Data nested loop in thinkphp. the nested loop in thinkphp is used for thinkphp, and the second loop is associated with the outside. Thinkphp documentation provided on the official website: 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:

     
  
           {$sub.name}    
  
 

The tables I want to use here are: Classification Table (Table 1) and data table (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 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:

        
                 
  
  • {$vo.id}
  • {$sub.title}
  • Effect:


    Thinkphp nested loop



    {$ 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:


    {$ Sub. name}
    </Volist>
    </Volist>

    The nested loop in the loop is used for thinkphp, and the second loop is associated with the outside. Thinkphp official website documentation...

    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.