代码如下:
PHP
$conn=MysqL_connect("localhost","root","myoa888");
MysqL_select_db("lost63",$conn) or die("select db error");
$sql[]="Create TABLE `lost63`.`dd_book_class` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`classname` VARCHAR( 50 ) NOT NULL,
`classid` INT NOT NULL
)";
$sql[]="insert `dd_book_class` (classname,classid) values ('小说',0)";
$sql[]="insert `dd_book_class` (classname,classid) values ('文艺',classid) values ('青春',classid) values ('励志/成功',classid) values ('少儿',classid) values ('悬疑',1)";
$sql[]="insert `dd_book_class` (classname,classid) values ('言情',classid) values ('职场',classid) values ('文学',2)";
$sql[]="insert `dd_book_class` (classname,classid) values ('科普',5)";
//print_r($sql);
/* -- insert test data -- */
foreach($sql as $value){
MysqL_query($value) or die("insert data error");
} $class_arr=array();
$recordset=MysqL_query("select * from `dd_book_class`");
while($row=MysqL_fetch_array($recordset)){
$class_arr[]=array($row['id'],$row['classname'],$row['classid']);
}
function classtree($n,$id){
global $class_arr;
$n = str_pad('',$n,'-',STR_PAD_RIGHT);
$n = str_replace("-"," ",$n);
for($i=0;$iif($class_arr[$i][2]==$id){
echo $n.'┠[1].'
';
classtree($n+1,$class_arr[$i][0]);
}
}
}
classtree(0,0);
?>
原文链接:https://www.f2er.com/php/28850.html$conn=MysqL_connect("localhost","root","myoa888");
MysqL_select_db("lost63",$conn) or die("select db error");
$sql[]="Create TABLE `lost63`.`dd_book_class` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
`classname` VARCHAR( 50 ) NOT NULL,
`classid` INT NOT NULL
)";
$sql[]="insert `dd_book_class` (classname,classid) values ('小说',0)";
$sql[]="insert `dd_book_class` (classname,classid) values ('文艺',classid) values ('青春',classid) values ('励志/成功',classid) values ('少儿',classid) values ('悬疑',1)";
$sql[]="insert `dd_book_class` (classname,classid) values ('言情',classid) values ('职场',classid) values ('文学',2)";
$sql[]="insert `dd_book_class` (classname,classid) values ('科普',5)";
//print_r($sql);
/* -- insert test data -- */
foreach($sql as $value){
MysqL_query($value) or die("insert data error");
} $class_arr=array();
$recordset=MysqL_query("select * from `dd_book_class`");
while($row=MysqL_fetch_array($recordset)){
$class_arr[]=array($row['id'],$row['classname'],$row['classid']);
}
function classtree($n,$id){
global $class_arr;
$n = str_pad('',$n,'-',STR_PAD_RIGHT);
$n = str_replace("-"," ",$n);
for($i=0;$i
echo $n.'┠[1].'
';
classtree($n+1,$class_arr[$i][0]);
}
}
}
classtree(0,0);
?>