时间:2021-07-01 10:21:17 帮助过:4人阅读
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;
}
?>
include "comm.php";
//获取分类菜单
$arr=getTree();
$arrone=getFlone(59);
$arrtwo=getFltwo(93);
$arrmenu=getFlmenu(59);
print_r($arrmenu);
//获取分类树 www.2cto.com
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;
}
?>
[php]
[html] 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] => 时政
[3] => 0-59-93
[flpath] => 0-59-93
[4] => 时政
[fldes] => 时政
[5] => 时政
[keyword] => 时政
[tt] => Array
(
[0] => Array
(
[0] => 102
[flid] => 102
[1] => 98
[flpid] => 98
[2] => 医疗
[fltitle] => 医疗
[3] => 0-59-93-98
[flpath] => 0-59-93-98
[4] => 医疗
[fldes] => 医疗
[5] => 医疗
[keyword] => 医疗
)
[1] => Array
(
[0] => 103
[flid] => 103
[1] => 98
[flpid] => 98
[2] => 卫生
[fltitle] => 卫生
[3] => 0-59-93-98
[flpath] => 0-59-93-98
[4] => 卫生
[fldes] => 卫生
[5] => 卫生
[keyword] => 卫生
)
)
)
[1] => Array
(
[0] => 99
[flid] => 99
[1] => 93
[flpid] => 93
[2] => 民生
[fltitle] => 民生
[3] => 0-59-93
[flpath] => 0-59-93
[4] => 民生
[fldes] => 民生
[5] => 民生
[keyword] => 民生
[tt] => Array
(
[0] => Array
(
[0] => 104
[flid] => 104
[1] => 99
[flpid] => 99
[2] => 税费
[fltitle] => 税费
[3] => 0-59-93-99
[flpath] => 0-59-93-99
[4] => 税费
[fldes] => 税费
[5] => 税费
[keyword] => 税费
)
[1] => Array
(
[0] => 105
[flid] => 105
[1] => 99
[flpid] => 99
[2] => 住房
[fltitle] => 住房
[3] => 0-59-93-99
[flpath] => 0-59-93-99
[4] => 住房
[fldes] => 住房
[5] => 住房
[keyword] => 住房
)
)
)
)
)
[1] => Array
(
[0] => 96
[flid] => 96
[1] => 59
[flpid] => 59
[2] => 娱乐新闻
[fltitle] => 娱乐新闻
[3] => 0-59
[flpath] => 0-59
[4] => 娱乐新闻
[fldes] => 娱乐新闻
[5] => 娱乐新闻
[keyword] => 娱乐新闻
[two] => Array
(
[0] => Array
(
[0] => 100
[flid] => 100
[1] => 96
[flpid] => 96
[2] => 八卦
[fltitle] => 八卦
[3] => 0-59-96
[flpath] => 0-59-96
[4] => 八卦
[fldes] => 八卦
[5] => 八卦
[keyword] => 八卦
[tt] => Array
(
)
)
[1] => Array
(
[0] => 101
[flid] => 101
[1] => 96
[flpid] => 96
[2] => 明星
[fltitle] => 明星
[3] => 0-59-96
[flpath] => 0-59-96
[4] => 明星
[fldes] => 明星
[5] => 明星
[keyword] => 明星
[tt] => Array
(
)
)
)
)
[2] => Array
(
[0] => 97
[flid] => 97
[1] => 59
[flpid] => 59
[2] => 国外新闻
[fltitle] => 国外新闻
[3] => 0-59
[flpath] => 0-59
[4] => 国外新闻
[fldes] => 国外新闻
[5] => 国外新闻
[keyword] => 国外新闻
[two] => Array
(
[0] => Array
(
[0] => 106
[flid] => 106
[1] => 97
[flpid] => 97
[2] => 美国
[fltitle] => 美国
[3] => 0-59-97
[flpath] => 0-59-97
[4] => 美国
[fldes] => 美国
[5] => 美国
[keyword] => 美国
[tt] => Array
(
[0] => Array
(
[0] => 107
[flid] => 107
[1] => 106
[flpid] => 106
[2] => 纽约
[fltitle] => 纽约
[3] => 0-59-97-106
[flpath] => 0-59-97-106
[4] => 纽约
[fldes] => 纽约
[5] => 纽约
[keyword] => 纽约
)
)
)
)
)
)
摘自 chaojie2009的专栏http://www.bkjia.com/PHPjc/478378.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/478378.htmlTechArticle//数据库表 ?php include comm.php; //获取分类菜单 $arr=getTree(); $arrone=getFlone(59); $arrtwo=getFltwo(93); $arrmenu=getFlmenu(59); print_r($arrmenu); //获取分类树...