ホームページ >バックエンド開発 >PHPチュートリアル >PHP 無制限のカテゴリ読み取りマルチレベル メニュー_PHP チュートリアル

PHP 無制限のカテゴリ読み取りマルチレベル メニュー_PHP チュートリアル

WBOY
WBOYオリジナル
2016-07-13 17:48:581625ブラウズ

//データベーステーブル



「comm.php」を含めます。
//カテゴリーメニューを取得します

$arr=getTree(); $arrone=getFlone(59); $arrtwo=getFltwo(93); $arrmenu=getFlmenu(59); print_r($arrmenu);

//分類木を取得します
関数 getTree(){
グローバル $db
$sql="fenlei から flid、flpid、flpath、fltitle、fldes、キーワードを選択します
"; $rs=$db->クエリ($sql); $data=配列(); While ($row=$db->fetch_array($rs)){
$data[]=$row; }
$data を返します。 }
//アクティビティの第 1 レベルの分類 最上位の分類 ID は 59 であることに注意してください
関数 getFlone($flpid){
グローバル $db
$sql="select * from fenlei where flpid={$flpid} flid で注文"; $rs=$db->クエリ($sql); $data=配列(); While ($row=$db->fetch_array($rs)){
$data[]=$row; }
$data を返します。 }
//アクティビティの二次分類
関数 getFltwo($flpid){
グローバル $db
$sql="select * from fenlei where flpid={$flpid} flid で注文"; $rs=$db->クエリ($sql); $data=配列(); While ($row=$db->fetch_array($rs)){
$data[]=$row; }
$data を返します。 }
//ループしてメニューを取得します。このデータベースの最上位の親カテゴリ ID は 59 です
関数 getFlmenu($flpid){
グローバル $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; }
$arr を返します
}

?>
「comm.php」を含める;

//カテゴリーメニューを取得します

$arr=getTree();
$arrone=getFlone(59);
$arrtwo=getFltwo(93);
$arrmenu=getFlmenu(59);
print_r($arrmenu);


//分類ツリーを取得 www.2cto.com
関数 getTree(){
グローバル $db;
$sql="fenlei の flid 順に flid,flpid,flpath,fltitle,fldes,keyword を選択";
$rs=$db->クエリ($sql);
$data=array();
while ($row=$db->fetch_array($rs)){
$data[]=$row;
}
$data を返します;
}
//アクティビティの第 1 レベルの分類 最上位の分類 ID は 59 であることに注意してください
関数 getFlone($flpid){
グローバル $db;
$sql="select * from fenlei where flpid={$flpid} order by flid";

$rs=$db->クエリ($sql);

$data=array();

while ($row=$db->fetch_array($rs)){

$data[]=$row;
}
$data を返します;
}
//アクティビティ二次分類

関数 getFltwo($flpid){

グローバル $db;
$sql="select * from fenlei where flpid={$flpid} order by flid";
$rs=$db->クエリ($sql);
$data=array();
while ($row=$db->fetch_array($rs)){
$data[]=$row;
}
$data を返します;
}
//ループしてメニューを取得します。このデータベースの最上位の親カテゴリ ID は 59 です
関数 getFlmenu($flpid){
グローバル $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;
 }
 $arr を返します;
}

?>

[php]

[html] 配列 
(
[0] => 配列
(
[0] => 93 [フリップ] => 93
[1] => 59 [flpid] => [2] = & gt;国内ニュース
[fltitle] => 国内ニュース
[3] => [flpath] => 0-59
[4] => 国内ニュース
[fldes] => 国内ニュース
[5] => 国内ニュース
【キーワード】 = & gt; 国内ニュース
[2] => 配列
                                                              以来                                                                                                                                                                                                  [フリップ] => 98
                                                                                                                                                  [flpid] => 93
                                                                                                                                                                                                                                                           [fltitle] => 時事問題
                                                                                                                                                                  [flpath] => 0-59-93
                                                                                                                                                                                                                                                        [fldes] => 時事問題
                                                                                                                                                                                                                                                                   [キーワード] =>時事問題
[tt] => 配列
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
                                                                                                                                                                                                     
)

以来                                                                                                                                                                                                    [フリップ] => 99
                                                                                                                                                  [flpid] => 93
人々の暮らし
[fltitle] => 人々の生活
                                                                                                                                                                  [flpath] => 0-59-93
人々の暮らし
[fldes] => 人々の生活
人々の暮らし
int by [tt] => 配列
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                  
)

)

)

[1] => 配列
(
[0] => 96
[フリップ] => 96
[1] => 59 [flpid] => [2] => [fltitle] => エンターテイメント ニュース
[3] => [flpath] => 0-59
[4] => エンターテインメント ニュース
[fldes] => エンターテインメント ニュース
[5] => エンターテインメント ニュース
[キーワード] => エンタメニュース
[2] => 配列
                                                              以来                                                                                                                                                                                           [フリップ] => 100
                                                                                                                               [flpid] => 96
                                                                                                                                                                                                                                                                        [fltitle] =>ゴシップ
                                                                                                                                                                       [flpath] => 0-59-96
                                                                                                                                                                                                                                                                  [fldes] => うわさ話
                                                                                                                                                                                                                                                                          [キーワード] => [tt] => 配列
                                                                                                                                                                                                                                                                                                                  
)

以来                                                                                                                                                                                                  [フリップ] => 101
                                                                                                                               [flpid] => 96
                                                                                                                                                                                                                                        [fltitle] =>有名人
                                                                                                                                                                       [flpath] => 0-59-96
                                                                                                                                                                                                                                                           [fldes] => スター
                                                                                                                                                                                                                                      以来 [tt] => 配列
                                                                                                                                                                                                                                                                                                                  
)

)

)

[2] => 配列
(
[0] => 97 [フリップ] => 97
[1] => 59 [flpid] => [2] => [fltitle] => [3] => [flpath] => 0-59
[4] => 海外ニュース
[fldes] => [5] => 海外ニュース
[キーワード] => [2] => 配列
                                                              以来                                                                                                                                                                                                 [フリップ] => 106
                                                                                                                                      [flpid] => 97
                                                                                                                                                                                       [fltitle] => 米国
                                                                                                                                                        [flpath] => 0-59-97
                                                                                                                                                                                                           以来                                                                                                                                                                                                  」 [tt] => 配列
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                  
)

)

)

)

chaojie2009 さんのコラムより抜粋

www.bkjia.com本当http://www.bkjia.com/PHPjc/478378.html技術記事 //データベーステーブル?php include comm.php; //カテゴリメニューを取得 $arrone=getFltwo(93); $ arrmenu); //分類ツリーを取得します...
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。