Implementation of infinite level menu_PHP tutorial

WBOY
Release: 2016-07-21 16:07:41
Original
884 people have browsed it


I will provide a test tomorrow (already today, haha) Let everyone take a look at the page (because I can only dial up the Internet in the dormitory, and the IP address is not fixed) ($SearchPattern,$BaseNum){
global $Tree;//Declare the handle to connect to the database as global
$Sql="select DepartmentId,DepartmentName from test where DepartmentId like '$SearchPattern'"; //Find children Node
$QueryChild=$Tree->query($Sql);            $Space=" ";
for($j=0;$j<((strlen($SearchPattern)/3)-$BaseNum);$j++)
Show the node in front of Distance, the html of the spaces here is automatically replaced with " " ID like '$ChildDepartment'"; //Find the child node of the child node ($Result[0]) ; //Set the table Id
                                                                                                                                                                                                                                                                                            <1){/ /If the node of the child node is not found, the "-" picture is displayed
                                                ;< A href="process.php?SearchPattern=" class="F1">
                                                                                     ;?}else{                                                                                                                                                               ="javascript:expands('< ?=$TableId?>','')" style="cursor:hand">
;
                                                                                                                        lt;/table>
                                                                                                                                                                                                         ;






require("do_mySql.php");
$Tree = new DB_Sql;
$Tree->connect();//连接数据库,可根据需要换成自己的代码

  $Sql="select DepartmentId,DepartmentName from test where length(DepartmentId)=3";//提出最上层节点(祖宗节点),根据需要自己修改
  $Result=$Tree->query_first($Sql);
?>

                         
  
                         
                           
                             
      
                     
        
         
                   
                     
              
         
        
                                                                                      
        
          $FirstDepartment=$Result[0];
$BaseNum=strlen($FirstDepartment)/3;//计算层数,其实这个有点多余,因为其必为第一层
$SearchPattern=$FirstDepartment."___"; //设置查找条件
ListChildTree($SearchPattern,$BaseNum); //显示祖宗节点的孩子节点
?>
        

        

       

                                                                                              body>



Because the test table is designed very simply:

CREATE TABLE test (
id mediumint(8) unsigned NOT NULL auto_increment, #Serial number
DepartmentId varchar(100) NOT NULL default '', #Unit code
DepartmentName varchar(100) NOT NULL default '', #Unit Name
KEY id (id)
)

I won’t show you the code for data insertion here (it’s easy to write, I believe everyone can write it)

The rules of the data table are:

001 is the first level (if 999 is not enough, please add it yourself)
001001 is the first child node of 001, 001002 is the second child node of 001
001001001 is the first child node of 001001, and so on...

I only set one "ancestor" (001) here, so I call it directly in the program, you can do it yourself as needed Set up and make simple modifications to the code!

Okay, that’s it. If you have any questions, please feel free to discuss them with me! Best to wish you all a great day at work!
Smoke a cigarette before going to bed! So tired! (Because I just wrote a webFtp, if any brothers and sisters need it, please email me)
*/


?>





http://www.bkjia.com/PHPjc/314993.html

www.bkjia.com

true

TechArticle?/* I saw many friends asking about unlimited level menus (in fact, there are still levels, After all, it is subject to a convenient condition, such as: database field type, etc.),...
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