首頁 >php教程 >php手册 >php无限分级类

php无限分级类

WBOY
WBOY原創
2016-06-07 11:43:411368瀏覽

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