Home > Article > Backend Development > Implementation of infinite level menu_PHP tutorial
/* I saw many friends asking questions about unlimited level menus (in fact, there are still levels in theory, after all, they are subject to convenient conditions, such as: database field types, etc.), I once used Boss ( The code provided by Nagging) has been used to write an unlimited level menu, but the effect is not very good (visually), so I took advantage of the "dead of night" to write this "unlimited level menu". In fact, the reason is very simple, mainly data The design of the table, as well as the use of recursive methods (if I have time, I will use the median sorting method), I will give the design of the data structure below (very simple), here I did not add a vertical dotted line ( The dotted line of Windows Explorer), and I also fixed the Sql statement. You can modify it according to your needs!If you have any questions, please contact me: msn:banneryue@sina.com, QQ: 7665656, E_mail: yuepengfei@mail.banner.com.cn
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==trim($Result[0])?>" class="F1">=$Result[1]?>
;?}else{ ="javascript:expands('< ?=$TableId?>','=$TablePic?>')" style="cursor:hand">=$Result[1] ?>
;
lt;/table>
;
body> /* Table structure design 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 Statement: 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 Previous article:A function to view session content_PHP tutorialNext article:A function to view session content_PHP tutorial Related articlesSee more |