Home  >  Article  >  Backend Development  >  How to implement nested loops of data by category in Thinkphp, thinkphp nesting_PHP tutorial

How to implement nested loops of data by category in Thinkphp, thinkphp nesting_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:15:45761browse

How to implement nested loops of data by category in Thinkphp, thinkphp nesting

The example in this article describes how to implement nested loops of data by category in Thinkphp. Share it with everyone for your reference. The specific implementation method is as follows:

When doing thinkphp, you need to use nested loops inside loops, and the second loop is related to the outside one.
The document given by thinkphp official website is:

Copy code The code is as follows:


{$sub.name}

The tables I want to use here are: classification table (Table 1), data table (Table 2)
The effect to be achieved is:








In fact, the principle is to first find the classification table (Table 1), then query Table 1 and Table 2, and finally output it in the form of a two-dimensional array

The background code is as follows:

Copy code The code is as follows:
$m=M('Table 1');
$m1=M('Table 2');

$parent=$m->select();
foreach($parent as $n=> $val){
$parent[$n]['voo']=$m1->where('Fields in table 2 associated with table 1='.$val['table 1id'].'')->select( );
}
$this->assign('list',$parent);
$this->display();

Foreground output display:

Copy code The code is as follows:

  • {$vo.id}


  •                                                                                               


    The effect is as shown below:

    I hope this article will be helpful to everyone’s ThinkPHP programming design.

    thinkphp nested loop


    {$sub}



    How to nest loops in thinkphp

    http://www.bkjia.com/PHPjc/903475.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/903475.htmlTechArticleHow to implement nested loops of data in Thinkphp by category, thinkphp nesting This article describes the example of nesting data in Thinkphp by category Set of loop implementation methods. Share it with everyone for your reference. Specific actual...
    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn