首页  >  文章  >  php教程  >  php无限分级类

php无限分级类

WBOY
WBOY原创
2016-06-07 11:43:411348浏览

php无限分级类,网站栏目的无分级,以树形结构显示
/*使用递归方式遍历无限分级类*/
//必须获得顶级栏目
//加载数据库类
$ROOT = substr(dirname(__FILE__),0,-4);
include $ROOT.'/include/common.inc.php';
/*$dsql 为数据库类*/
$sql = "SELECT id,typename FROM dede_arctype where reid=0 ORDER BY id ASC";
$dsql->Execute('me',$sql);
$tpc = '';
while($row = $dsql->GetArray('me')){
$topc[$row['id']] = $row;
$topid[] = $row['id'];
blc($row['id'],null);
}

function blc($pid,$ppid)
{
global $dsql , $topc;
$rows = '';
$sql = "SELECT id,reid,typename FROM dede_arctype where reid=$pid ORDER BY id ASC";
$dsql->Execute('idme',$sql);

while($row = $dsql->GetArray('idme')){
$topc[$pid]['son'][$row['id']] = $row;
$topc[$ppid]['son'][$pid]['son'][$row['id']] = &$topc[$pid]['son'][$row['id']];
$rows[] = $row;
}

if($rows == '')
{
return;
}
else
{
foreach($rows as $varid){
blc($varid['id'],$varid['reid']);
}
return;
}

}
$topkey = array_keys($topc);
$toplength = count($topkey);

foreach($topid as $now_id)
{

for($i=0;$i {
if($topkey[$i] == $now_id) $reTOP[$topkey[$i]] = $topc[$topkey[$i]];
}
}
unset($topc);

$str = '';
function echotra($row){
global $str;
//if(empty($row['son'])) return;
foreach($row as $id=>$value){
$str .= '

  • '.$value['typename'].'
  • ';
    if($value['son']){
    $str .='
      ';
      echotra($value['son']);
      $str .= '
    ';
    }
    }
    }

    echotra($reTOP);
    echo $str;

    AD:真正免费,域名+虚机+企业邮箱=0元

    声明:
    本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn