Database Design:
--
-- Database: 'test'
--
----------------------------------------------------------
--
-- Table structure 'menu'
--
Create Table if not exists 'menu '(
'Id' int (10) unsigned not null auto_increment,
'Pid 'int (11) not null,
'Title' varchar (200) not null,
'Remark' varchar (200) not null,
Primary Key ('id ')
) Engine = MyISAM default charset = utf8 auto_increment = 9;
--
-- Export the data 'menu 'in the table'
--
Insert into 'menu '('id', 'pid', 'title', 'remark') Values
(1, 0, 'company', 'root '),
(2, 1, 'Finance authorization', 'authorization '),
(3, 1, 'sales Department ', 'department '),
(4, 1, 'personnel authorization ',''),
(5, 2, 'account ',''),
(6, 3, 'salesman ',''),
(7, 4, 'personnel manager ','');
--------------------------------------------------------
PHP code:
--------------------------------------------------------
<? PHP
Include "config. php ";
Include "mysql. php ";
$ Db = new MySQL ('test'); // Several Simple classes that you can understand without listing. Just instantiate a database connection.
Function rootmenu ($ PID, $ n ){
Global $ arr, $ dB;
$ SQL = "select * From menu where 'pid '= $ PID ";
$ Result = $ db-> query ($ SQL );
While ($ I = $ db-> fetch_array ($ result )){
$ I ["title"] = str_repeat ('--', $ N). $ I ["title"];
$ Arr [] = $ I;
Rootmenu ($ I ["ID"], ($ n + 4 ));
}
Return $ arr;
}
$ Arr = rootmenu (0, 0 );
?>
<Select id = "">
<Option value = "0" selected = "selected"> select a department </option>
<? PHP
For ($ I = 0; $ I <count ($ ARR); $ I ++ ){
?>
<Option value = "<? PHP echo $ arr [$ I] ["ID"]?> "> <? PHP echo $ arr [$ I] ["title"]?> </Option>
<? PHP }?>
</SELECT>
--------------------------------------------------------