In this paper, an example is given to describe the use of thinkphp Label implementation of the three-level loop code, the following steps:
1. The three-level loop requires a three-dimensional array, which implements the following code:
function Maketree ($pid, $level) {$map [' pid '] = $pid; $map [' level '] = $level; $result = $this->where ($map)->order (' R Ank ASC ')->findall (); if ($result) {foreach ($result as $key = = $value) {$title = $value [' Alias ']; $list [$title] [' id '] = $value [' id ']; $list [$title] [' pid '] = $value [' pid ']; $list [$title] [' Alias ']= $value [' Alias ']; $list [$title] [' title '] = $value [' title ']; $list [$title] [' level '] = $value [' Level ']; $list [$title] ["state"] = $value [' state ']; $list [$title] [' rank '] = $value [' Rank ']; if ($value [' Level ']<=3) {$list [$title] [' child '] = $this->_makesontree ($value [' id ']);} }} return $list; } function _makesontree ($pid) {$map [' pid '] = $pid; $result = $this->where ($map)->order (' Rank ASC ')->findall (); if ($result) {foreach ($result as $key = = $value) {$title = $value [' Alias ']; $list [$title] [' ID ']= $value [' id ']; $list [$title] [' pid ']= $value [' pid ']; $list [$title] [' Alias ']= $value [' Alias ']; $list [$title] [' title '] = $value [' title ']; $list [$title][' level ') = $value [' Level ']; $list [$title] ["state"] = $value [' state ']; $list [$title] [' rank '] = $value [' Rank ']; if ($this->haschild ($value [' ID '])) {//first determine if there is a third level subclass, the final array shape such as $result[' child ' [' grandchild ']; $list [$title] [' grandchild ']= $this->_makesontree ($value [' id ']); }}} return $list; } function Haschild ($id) {$result =d (' Learningchannel ')->where ("pid=". $id)->find (); if ($result) {return true; } else return false; }
2. Binding Volist Tags:
$result =d (' Learning ')->maketree (0,1); Dump ($result); $this->assign (' list ', $result);
3. Template section:
Selected >{$vo. alias} Selected >--{$child. alias} Selected >---{$grand. alias}