-- -- 数据库: `tree` -- CREATE DATABASE `tree` DEFAULT CHARACTER SET gb2312 COLLATE gb2312_chinese_ci; USE `tree`;
-- -- 表的结构 `class` --
CREATE TABLE `class` ( `id` int(11) NOT NULL auto_increment, `name` varchar(10) NOT NULL, `pid` int(11) NOT NULL, `depth` varchar(100) default '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=gb2312 AUTO_INCREMENT=30 ;
$link =mysql_connect('localhost','root','root'); mysql_select_db('tree'); mysql_query ( 'set names GBK' ); if($_GET['act']=='add'){ $name=$_POST['name']; if($name=='') exit('name not null'); $pid=$_POST['pid']; if($pid !=0){ $sql="select * from class where id=".$pid; $result =mysql_query($sql); $row = mysql_fetch_array($result); $depth=$row['depth'].','.mysql_insert_id();//$getID即为最后一条记录的ID }else{ $depth=0; } $sql="INSERT INTO class(name,pid,depth) VALUES('".$name."','".$pid."','".$depth."')"; $result =mysql_query($sql); if(!$result){ exit("shibai $sql"); }else{ exit("chenggong"); } } ?>
//$sql = "select * from `class` order by sort asc, id Desc"; //$sql="select * from class where pid=0"; //$result =mysql_query($sql); //while($row = mysql_fetch_array($result)){ //$class_arr[] = array($row['id'],$row['name'],$row['classid'],$row['sort']); // echo $row['name'].$row['id'].'---'.$row['pid'].' '; sorttree(0);