PHP递归无限分类的 如何统计总条数 以及对显示的结果进行分页?比如设置为每页显示10个 。
functiongetTree($data,$pId,$level=0){$tree='';foreach($dataas$k=>$v){if($v['teacherbi...
function getTree($data, $pId, $level=0)
{
$tree = '';
foreach($data as $k => $v)
{
if($v['teacherbianhao'] == $pId)
{ //父亲找到儿子
unset($data[$k]);//注销当前节点数据,减少已无用的遍历
$v['teacherbianhao'] = getTree($data, $v['bianhao'],$level+1);
$tree[] = $v;
}
}
return $tree;
}
//这个位置带入参数
$tree = getTree($data, $bh,0);
function procHtml($tree)
{
$html = '';
foreach($tree as $t)
{
if($t['teacherbianhao'] == '')
{
$html .= "<li>{$t['nickname']}{$t['bianhao']}</li>";
}
else
{
// $html .= "<li>".$t['nickname'].$t['bianhao']."共".$t['level']."人";
$html .= "<li>".$t['nickname'].$t['bianhao'];
$html .= procHtml($t['teacherbianhao']);
$html = $html."</li>";
}
}
return $html ? '<ul>'.$html.'</ul>' : $html ;
}
echo procHtml($tree); 展开
{
$tree = '';
foreach($data as $k => $v)
{
if($v['teacherbianhao'] == $pId)
{ //父亲找到儿子
unset($data[$k]);//注销当前节点数据,减少已无用的遍历
$v['teacherbianhao'] = getTree($data, $v['bianhao'],$level+1);
$tree[] = $v;
}
}
return $tree;
}
//这个位置带入参数
$tree = getTree($data, $bh,0);
function procHtml($tree)
{
$html = '';
foreach($tree as $t)
{
if($t['teacherbianhao'] == '')
{
$html .= "<li>{$t['nickname']}{$t['bianhao']}</li>";
}
else
{
// $html .= "<li>".$t['nickname'].$t['bianhao']."共".$t['level']."人";
$html .= "<li>".$t['nickname'].$t['bianhao'];
$html .= procHtml($t['teacherbianhao']);
$html = $html."</li>";
}
}
return $html ? '<ul>'.$html.'</ul>' : $html ;
}
echo procHtml($tree); 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询