日期:2011-09-16  浏览次数:20443 次


//数据库表

<?php
include "comm.php";
//获取分类菜单
$arr=getTree();
$arrone=getFlone(59);
$arrtwo=getFltwo(93);
$arrmenu=getFlmenu(59);
print_r($arrmenu);
//获取分类树
function getTree(){
global $db;
$sql="select flid,flpid,flpath,fltitle,fldes,keyword from fenlei order by flid";
$rs=$db->query($sql);
$data=array();
while ($row=$db->fetch_array($rs)){
$data[]=$row;
}
return $data;
}
//活动一级分类 注意在这顶级分类id为 59
function getFlone($flpid){
global $db;
$sql="select * from fenlei where flpid={$flpid} order by flid";
$rs=$db->query($sql);
$data=array();
while ($row=$db->fetch_array($rs)){
$data[]=$row;
}
return $data;
}
//活动二级分类
function getFltwo($flpid){
global $db;
$sql="select * from fenlei where flpid={$flpid} order by flid";
$rs=$db->query($sql);
$data=array();
while ($row=$db->fetch_array($rs)){
$data[]=$row;
}
return $data;
}
//循环获取菜单,此数据库顶级父分类id为 59
function getFlmenu($flpid){
global $db;
$arr=getFlone($flpid);
foreach ($arr as &$v) {
$arrt=getFlone($v["flid"]);
foreach ($arrt as &$vl){
$arrtt=getFlone($vl["flid"]);
$vl["tt"]=$arrtt;
}
$v["two"]=$arrt;
}
return $arr;
}
?>
Array
(
[0] => Array
(
[0] => 93
[flid] => 93
[1] => 59
[flpid] => 59
[2] => 国内新闻
[fltitle] => 国内新闻
[3] => 0-59
[flpath] => 0-59
[4] => 国内新闻
[fldes] => 国内新闻
[5] => 国内新闻
[keyword] => 国内新闻
[two] => Array
(
[0] => Array
(
[0] => 98
[flid] => 98
[1] => 93
[flpid] => 93
[2] => 时政
[fltitle] => 时政 本文链接http://www.cxybl.com/html/wlbc/Php/20121120/34051.html