PHPÎÞÏÞ¼¶·ÖÀàʾÀý£¬Ò»¸ö¼òµ¥µÄPHPÎÞÏÞ¼¶·ÖÀàʾÀý£¬±¾´úÂëÊÇÔڸĽøÍøÉϵÄһʵÀý£¬×ªÒƺÍÌí¼Ó¹¦ÄÜÒѾ±¾È˲âÊÔͨ¹ý£¬·ÅÐÄʹÓã¬Ö±½ÓÔËÐе±Ç°Îļþ±ã¿ÉPHP.
±¾·ÖÀà·½·¨µÄÓÅÊÆ£º
1£¬Êý¾Ý¿â½á¹¹¼òµ¥£¬Ö»ÓÐ cid pid name
Èý¸ö×ֶΣ¬ÎÞÈκÎÈßÓà×Ö¶Î
2£¬²»Ê¹Óõݹé²éѯ£¬ËùÓвÙ×÷Ö»ÐèÒ»ÌõsqlÓï¾ä
3£¬ËùÓÐÊý¾ÝÔÚ¶ÁÈ¡Ò»´ÎÊý¾Ý¿âºó£¬ÔÚÊý×éÄÚ½øÐзÖÎö´¦Àí£¬½ÚÊ¡Êý¾Ý¿â·þÎñÆ÷×ÊÔ´
<?php header("Content-type: text/html; charset=utf-8"); /** +---------------------------------------------------------- * franklin Àý×Ó +---------------------------------------------------------- * ÎļþÃû³Æ scort.php +---------------------------------------------------------- * ÎļþÃèÊö ÎÞÏÞ¼¶·ÖÀàʾÀý +---------------------------------------------------------- * ×÷ Õß franklin<franklin@co-insight.com> +---------------------------------------------------------- * ʱ ¼ä 2011-1-18 +---------------------------------------------------------- */ //ÏÈ´´½¨Ò»¸öÊý¾Ý¿â /*CREATE TABLE IF NOT EXISTS `scortclass` ( `cid` mediumint(8) unsigned NOT NULL auto_increment, `pid` mediumint(8) unsigned NOT NULL, `cname` varchar(50) NOT NULL, PRIMARY KEY (`cid`), KEY `pid` (`pid`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; */ //Á¬½ÓÊý¾Ý¿â $link = mysql_connect('localhost','root','123') or die(mysql_error()); mysql_select_db('test',$link); //ÎÞÏÞ·ÖÀàÀà¿â class SortClass{ var $data = array(); var $child = array(-1=>array()); var $layer = array(-1=>-1); var $parent = array(); var $link; var $table; function SortClass($link, $table){ $this->setNode(0, -1, '¶¥¼«½Úµã'); $this->link = $link; $this->table = $table; $node = array(); mysql_query("set names 'utf8'"); $results = mysql_query('select * from '.$this->table.'',$this->link); while($node = @mysql_fetch_assoc($results)){ $this->setNode($node['cid'],$node['pid'],$node['cname']); } } function setNode ($id, $parent, $value){ $parent = $parent?$parent:0; $this->data[$id] = $value; $this->child[$id] = array(); $this->child[$parent][] = $id; $this->parent[$id] = $parent; $this->layer[$id] = !isset($this->layer[$parent])? 0 : $this->layer[$parent] + 1; } function getList ($tree, $root= 0){ foreach ($this->child[$root] as $key=>$id){ $tree[] = $id; if ($this->child[$id]) $this->getList($tree, $id); } } function getValue ($id){return $this->data[$id];} function getLayer ($id, $space = false){ return $space?str_repeat($space, $this->layer[$id]):$this->layer[$id]; } function getParent ($id){return $this->parent[$id];} function getParents ($id){ while ($this->parent[$id] != -1){ $id = $parent[$this->layer[$id]] = $this->parent[$id]; } ksort($parent); reset($parent); return $parent; } function getChild ($id){return $this->child[$id];} function getChilds ($id = 0){ $child = array($id); $this->getList($child, $id); return $child; } function addNode($pid,$name){ //die("insert into $this->table (`pid`,`cname`) values ('$pid','$name')"); //$sql = "insert into `class` (`pid`,`cname`) values ('0','°®Çé')"; mysql_query('set names utf8'); mysql_query("insert into $this->table (`pid`,`cname`) values ('$pid','$name')"); } function modNode($cid, $newName){ mysql_query("update $this->table set `cname`='$newName' where `cid` = $cid",$this->link) or die(mysql_error()); } function delNode($cid){ $allChilds = $this->getChilds($cid); $sql =''; if(emptyempty($allChilds)){ $sql = "delete from $this->table where `cid` = $cid"; }else{ $sql = 'delete from '.$this->table.' where `cid` in ('.implode(',',$allChilds).','.$cid.')'; } mysql_query($sql,$this->link); } function moveNode($cid, $topid){ mysql_query("update $this->table set `pid`=$topid where `cid` = $cid", $this->link); } } //º¯Êý function back(){ echo '<script language="javascript">[removed].href="cache_index.php?"+new Date().getTime();</script>'; exit; } //Éù³Éselect function makeSelect($array,$formName){ global $tree; $select = '<select name="'.$formName.'">'; foreach ($array as $id){ echo $id; $select.='<option value="'.$id.'">'.$tree->getLayer($id, '|-').$tree->getValue($id)."</option>"; } return $select.'</select>'; } $tree = new SortClass($link,'`sortclass`'); $op = !emptyempty($_POST['op']) ? $_POST['op'] : $_GET['op']; if(!emptyempty($op)){ if($op=='add'){ $tree->addNode($_POST['pid'],$_POST['cname']); //back(); } if($op=='mod'){ $tree->modNode($_POST['cid'],$_POST['cname']); //back(); } if($op=='del'){ $tree->delNode($_GET['cid']); //back(); } if($op=='move'){ print_r($_POST['who']); $tree->moveNode($_POST['who'],$_POST['to']); back(); } } $category = $tree->getChilds(); ?> <style type="text/css"> body{font-size:12px;} ul{list-style:none;} a{cursor:pointer;} </style> <script language="javascript"> function $(e){return document.getElementById(e);} function mod(cid){ $('cid').value=cid; $('op').value='mod'; $('name').style.border='1px solid red'; } </script> <form action="cache_index.php" method="POST"> Ãû³Æ:<input type="text" id="name" name="cname" /> Ìí¼Óµ½:<?=makeSelect($category,'pid')?><br /> <input type="hidden" id="op" name="op" value="add" /> <input type="hidden" id="cid" name="cid" /> <input type="submit" value="Submit" /> </form> <h3>Òƶ¯·ÖÀà</h3> <form action="cache_index.php" method="POST"> <?=makeSelect($category,'who')?>Òƶ¯µ½:<?=makeSelect($category,'to')?> <input type="hidden" id="op" name="op" value="move" /> <input type="submit" value="Submit" /> </form> <ul> <?php foreach ($category as $id){ echo '<li>'.$tree->getLayer($id, '|£ ').$tree->getValue($id).' <a href="cache_index.php?op=del&cid='.$id.'">Del</a> <a onclick="mod('.$id.')">Edit</a> </li>'; } ?> </ul>
Ч¹ûͼÈçÏ£º
Ô´ÂëÏÂÔØ£º PHPÎÞÏÞ¼¶·ÖÀàʾÀý
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ