📄 treefromdb.php
字号:
<?php
header("Content-type:text/xml");
require_once('config.php');
print("<?xml version=\"1.0\"?>");
?>
<tree id="0">
<?php
$link = mysql_pconnect($mysql_host, $mysql_user, $mysql_pasw);
$db = mysql_select_db ($mysql_db);
//Create database and table if doesn't exists
if(!$db){
//mysql_create_db($mysql_db,$link);
$sql = "Create database ".$mysql_db;
$res = mysql_query ($sql);
$sql = "use ".$mysql_db;
$res = mysql_query ($sql);
$sql = "CREATE TABLE tree (item_id INT UNSIGNED not null AUTO_INCREMENT,item_nm VARCHAR (200) DEFAULT '0',item_order INT UNSIGNED DEFAULT '0',item_desc TEXT ,item_parent_id INT UNSIGNED DEFAULT '0',PRIMARY KEY ( item_id ))";
$res = mysql_query ($sql);
if(!$res){
echo mysql_errno().": ".mysql_error()." at ".__LINE__." line in ".__FILE__." file<br>";
}
}
getLevelFromDB(0);
mysql_close($link);
//print one level of the tree, based on parent_id
function getLevelFromDB($parent_id){
$sql = "SELECT item_id, item_nm FROM tree WHERE item_parent_id=$parent_id ORDER BY item_order";
$res = mysql_query ($sql);
if($res){
while($row=mysql_fetch_array($res)){
print("<item id='".$row['item_id']."' text=\"". str_replace('"',""",$row['item_nm'])."\">");
getLevelFromDB($row['item_id']);
print("</item>");
}
}else{
echo mysql_errno().": ".mysql_error()." at ".__LINE__." line in ".__FILE__." file<br>";
}
}
?>
</tree>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -