--
-- 数据库: `test`
--
-- --------------------------------------------------------
--
-- 表的结构 `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 ;
--
-- 导出表中的数据 `menu`
--
INSERT INTO `menu` (`ID`, `PID`, `TITLE`, `REMARK`) VALUES
(1, 0, '公司', '根'),
(2, 1, '财务部', '部门'),
(3, 1, '销售部', '部门'),
(4, 1, '人事部', ''),
(5, 2, '会计', ''),
(6, 3, '业务员', ''),
(7, 4, '人事总管', '');
--------------------------------------------------------
PHP代码:
--------------------------------------------------------
<?php
include "config.php";
include "mysql.php";
$db = new Mysql('test'); //几个简单的类,不用列出来大家也看得懂。就是实例化一个数据库连接而已。
function RootMenu ($PID,$n){
global $arr,$db;
$sql = "select * from menu where `PID` =$PID";
$result = $db->query($sql);
while ($i=$db->fetch_array($result)){
}
return $arr;
}
$arr = RootMenu(0,0);
?>
<select id="">
<option value="0" selected="selected">请选择部门</option>
<?php
for ($i=0;$i<count($arr);$i++) {
?>
<option value="<?php echo $arr[$i]["ID"] ?>"><?php echo $arr[$i]["TITLE"] ?></option>
<?php }?>
</select>
--------------------------------------------------------
效果如图: