本文以实例描述了ThinkPHP采用
1. 三级循环需要三维数组,实现代码如下:
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($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'])){ //先判断是否有第三级子类,最后的数组形如$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.绑定voList标签:
MakeTree(0,1); //dump($result); $this->assign('List',$result);3.模板部分:
>{$vo.alias}以上是内存溢出为你收集整理的ThinkPHP采用<volist>实现三级循环代码实例全部内容,希望文章能够帮你解决ThinkPHP采用<volist>实现三级循环代码实例所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)