//數據庫表
<?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;
}
?>
<?php
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] <pre>
<pre>[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] => 紐約
)
)
)
)
)
)