Home  >  Article  >  php教程  >  php无限分级类

php无限分级类

WBOY
WBOYOriginal
2016-06-07 11:43:411348browse

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元

    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