PHP unlimited category reading multi-level menu_PHP tutorial

WBOY
Release: 2016-07-13 17:48:58
Original
1575 people have browsed it

//Database table



include "comm.php";

//Get category menu

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


//Get classification tree
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;
}
//Activity first-level classification Note that the top-level classification id is 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;
}
//Activity secondary classification
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;
}
//Loop to get the menu, the top parent category id of this database is 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";

//Get the category menu

$arr=getTree();

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

//Get the classification tree 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;
}
//Activity first-level classification Note that the top-level classification id is 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;
}
//Activity secondary classification
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;
}
//Loop to get the menu, the top parent category ID of this database is 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] =>                                                                                                                           [flid] =>                                                                                             [1] => 59                                                                                         [flpid] =>                                  [2] => Domestic News
                   [fltitle] => Domestic News
                                                                                                                                        [3] => 0-59                                                                     [flpath] =>                         [4] => Domestic News
               [fldes] => Domestic News
                            [5] => Domestic News
                                                                                                                              [keyword] =>                                                                                       [two] => (
                                                                                                                                                                                                                                                                 since (
                                                                                                                                                                [flid] => 98
                                                                                                                                                                                [flpid] => 93
                                                                                                                                                                                                                                                                                     ​  [fltitle] => Current Affairs
                                                                                                                                                                                                               [flpath] => 0-59-93
                                                                                                                                                                                                                                                                 ​  [fldes] => Current Affairs
                                                                                                                                                                                                                                                                 ​  [keyword] => Current Affairs
[tt] => Array
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         [flpath] => 0-59-93-98
                                                                                                                                                                                                              ​                                                                                                                                                                                                                           ​                                                                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                                                                                                                                                             [flid] => 103
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           [flpath] => 0-59-93-98
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                    
                                                                                                                                              
[1] => Array
(
                                                                                                                                                                            [flid] => 99
                                                                                                                                                                                [flpid] => 93
                                                                                                                                                                                                                                                                   because [fltitle] => People’s Livelihood
                                                                                                                                                                                                               [flpath] => 0-59-93
                                                                                                                                                                                                                                                                                    Since [fldes] => People’s Livelihood
                                                                                                                                                                                                                                                                                                         since [keyword] => people’s livelihood
[tt] => Array
                                                                                                                                                                                                                                                                                                                                                                                                                                                                       [flid] => 104
                                                                                                                                                                                                                                                                                                                                                                                ​                                                                                                                                [flpath] => 0-59-93-99
                                                                                                                                                                                                                                                              ​                                                                                                                                                                                                                  ​                                                                                                                                                                                                                                          
[1] => Array
                                                                                                                                                                                                                                 [flid] => 105
                                                                                                         [flpid] => 99
                                                                                                                               [fltitle] => Housing
                                                                                                                                      [flpath] => 0-59-93-99
                                                                                                                                          [fldes] => Housing
                                                                                                                                                                                                        ​                                                                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                    
                                                                                                                                              
)

)

[1] => Array
(
[0] = & gt; 96
                                                                                                    [flid] =>                                                                                             [1] => 59                                                                                         [flpid] =>                                 [2] => Entertainment News
                 [fltitle] => Entertainment News
                                                                                                                                        [3] => 0-59                                                                     [flpath] =>                                [4] => Entertainment News
                   [fldes] => Entertainment News
                          [5] => Entertainment News
                                                                                                                                  [keyword] =>                                                                                       [two] => (
                                                                                                                                                                                                                                                                 since (
                                                                                                                                                                                       [flid] => 100
                                                                                                                                                                           [flpid] => 96
                                                                                                                                                                                                                                                                                              ​  [fltitle] => Gossip
                                                                                                                                                                                                                         [flpath] => 0-59-96
                                                                                                                                                                                                                                                                                                    ​  [fldes] => Gossip
                                                                                                                                                                                                                                                                                                  ​  [keyword] => Gossip
[tt] => Array
                                                                                                                                                                                                                                                                
                                                                                                                                              
[1] => Array
(
                                                                                                                                                                      [flid] => 101
                                                                                                                                                                           [flpid] => 96
                                                                                                                                                                                                                                                         [fltitle] => Celebrity
                                                                                                                                                                                                                         [flpath] => 0-59-96
                                                                                                                                                                                                                                                                                 [fldes] => Star
                                                                                                                                                                                                                                                                                        [keyword] => Celebrity
[tt] => Array
                                                                                                                                                                                                                                                                
                                                                                                                                              
)

)

[2] => Array
(
                                                                                                                                                          [0] =>                                                                                                                     [flid] =>                                                                                             [1] => 59                                                                                         [flpid] =>                                 [2] => Foreign News
                  [fltitle] => Foreign News
                                                                                                                                        [3] => 0-59                                                                     [flpath] =>                          [4] => Foreign News
                                                                                              [fldes] =>                                 [5] => Foreign News
                                                                                                                              [keyword] =>                                                                                       [two] => (
                                                                                                                                                                                                                                                                 since (
                                                                                                                                                              [flid] => 106
                                                                                                                                                                                    [flpid] => 97
                                                                                                                                                                                                                                                                  since [fltitle] => United States
                                                                                                                                                                                                                       [flpath] => 0-59-97
                                                                                                                                                                                                                                                                            ​  [fldes] => United States
                                                                                                                                                                                                                                                                                     ​                                                                                                                                                                                                                       Since [tt] => Array
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          [flpid] => 106
                                                                                                                            [fltitle] => New York
                                                                                                                                      [flpath] => 0-59-97-106
                                                                                                                                                                                                       ​                                                                                                                                  [keyword] => New York
                                                                                                                                                                                                                                        
                                                                                                                                                                                                                         
                                                                                                                
)

)

)

Excerpted from chaojie2009’s column

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478378.htmlTechArticle//Database table?php include comm.php; //Get the category menu $arr=getTree(); $ arrone=getFlone(59); $arrtwo=getFltwo(93); $arrmenu=getFlmenu(59); print_r($arrmenu); //Get the classification tree...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template