Home >Backend Development >PHP Tutorial >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)){
$i["TITLE"] =str_repeat('--',$n).$i["TITLE"];
$arr[] =$i;
RootMenu($i["ID"],($n+4));
}
return $arr;
}
$arr = RootMenu(0,0);
?>