thinkphp data nesting loops, thinkphp nested loops _php Tutorials

Source: Internet
Author: User

thinkphp data nesting loops, thinkphp nested loops


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:

 
  
   
  "
  
   list
  
   " id=
  
   "
  
   vo
  
   ">    
  
   
    
   "
   
    vo[' Sub ']
   
    " id=
   
    "
   
    Sub
   
    ">
   
            {$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

Background code:

$m =m (' table 1');        $m 1=m (' table 2');        $parent=Select($m        ); foreach  as $n = $val) {            $parent [$n] ['voo']= $m 1->  where(' table 2 and table 1 are associated with fields ='. $val [' table 1id']. Select();        $this->assign ('list', $parent);        $this->display ();

The foreground output shows:

        
 
  
   
  "
  
   list
  
   " id=
  
   "
  
   vo
  
   ">                
  
   
  • {$vo. ID}
  • " vo[' Voo '" id= " Sub ">
  • {$sub. Title}
  • The effect is:


    thinkphp Nested Loops



    {$sub}
    </volist>
    </volist>

    How to loop output in thinkphp?

    You need to use the tag nesting, please refer to the ThinkPHP3.0 full development manual 8.21 tag nesting:


    {$sub. Name}
    </volist>
    </volist>

    http://www.bkjia.com/PHPjc/840768.html www.bkjia.com true http://www.bkjia.com/PHPjc/840768.html techarticle thinkphp data nesting loop, thinkphp nested loop to do thinkphp when the loop is nested loop inside, and the second loop is associated with the outside. Thinkphp's official website ...

  • 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.