[ת]»ùÓÚ×óÓÒÖµÅÅÐòµÄÎÞÏÞ·ÖÀàËã·¨
<?php /** * »ùÓÚ×óÓÒÖµÅÅÐòµÄÎÞÏÞ·ÖÀàËã·¨ * Êý¾Ý¿â½á¹ûΪ CREATE TABLE om_catagory ( CatagoryID int(10) unsigned NOT NULL auto_increment, Name varchar(50) default '', Lft int(10) unsigned NOT NULL default '0', Rgt int(10) unsigned NOT NULL default '0', PRIMARY KEY (id), KEY lft (lft), KEY rgt (rgt) ) * ¸ü¶àµÄ¹ØÓÚ×óÓÒÖµÅÅÐòµÄÀý×Ó * http://www.chinaunix.net/jh/27/239532.html(http://dev.mysql.com/tech-resources/articles/hierarchical-data.html) * @author [email]psdshow@yahoo.com.cn[/email] * @version 1.0 * @copyright psdshow * »¶Ó¹âÁÙÎҵĸöÈËÈÕÖ¾ http://www.dayanmei.com */ class sortclass { /** * Description * @var * @since 1.0 * @access private */ var $db; /** * Description * @var * @since 1.0 * @access private */ var $tablefix; /** * Short description. * ¹¹Ô캯Êý,ÒýÈëÊý¾Ý¿â²Ù×÷ÀຯÊý * Detail description * @param none * @global none * @since 1.0 * @access private * @return void * @update date time */ function sortclass() { global $db; $this->db=$db; $this->tablefix="om_"; } // end func /** * Short description. * Ôö¼ÓеķÖÀà * Detail description * @param none * @global none * @since 1.0 * @access private * @return void * @update date time */ function addsort($CatagoryID,$SortName) { if($CatagoryID==0){ $Lft=0; $Rgt=1; }else{ $Result=$this->checkcatagory($CatagoryID); //È¡µÃ¸¸ÀàµÄ×óÖµ,ÓÒÖµ $Lft=$Result['Lft']; $Rgt=$Result['Rgt']; $this->db->query("UPDATE `".$this->tablefix."catagory` SET `Lft`=`Lft`+2 WHERE `Lft`>$Rgt"); $this->db->query("UPDATE `".$this->tablefix."catagory` SET `Rgt`=`Rgt`+2 WHERE `Rgt`>=$Rgt"); } //²åÈë if($this->db->query("INSERT INTO `".$this->tablefix."catagory` SET `Lft`='$Rgt',`Rgt`='$Rgt'+1,`Name`='$SortName'")){ //$this->referto("³É¹¦Ôö¼ÓеÄÀà±ð","[removed]HISTORY.BACK(1)",3); return 1; }else{ //$this->referto("Ôö¼ÓеÄÀà±ðʧ°ÜÁË","[removed]HISTORY.BACK(1)",3); return -1; } } // end func /** * Short description. * ɾ³ýÀà±ð * Detail description * @param none * @global none * @since 1.0 * @access private * @return void * @update date time */ function deletesort($CatagoryID) { //È¡µÃ±»É¾³ýÀà±ðµÄ×óÓÒÖµ,¼ì²âÊÇ·ñÓÐ×ÓÀà,Èç¹ûÓоÍÒ»Æðɾ³ý $Result=$this->checkcatagory($CatagoryID); $Lft=$Result['Lft']; $Rgt=$Result['Rgt']; //Ö´ÐÐɾ³ý if($this->db->query("DELETE FROM `".$this->tablefix."catagory` WHERE `Lft`>=$Lft AND `Rgt`<=$Rgt")){ $Value=$Rgt-$Lft+1; //¸üÐÂ×óÓÒÖµ $this->db->query("UPDATE `".$this->tablefix."catagory` SET `Lft`=`Lft`-$Value WHERE `Lft`>$Lft"); $this->db->query("UPDATE `".$this->tablefix."catagory` SET `Rgt`=`Rgt`-$Value WHERE `Rgt`>$Rgt"); //$this->referto("³É¹¦É¾³ýÀà±ð","[removed]history.back(1)",3); return 1; }else{ //$this->referto("ɾ³ýÀà±ðʧ°ÜÁË","[removed]history.back(1)",3); return -1; } } // end func /** * Short description. * 1,ËùÓÐ×ÓÀà,²»°üº¬×Ô¼º;2°üº¬×Ô¼ºµÄËùÓÐ×ÓÀà;3²»°üº¬×Ô¼ºËùÓи¸Àà4;°üº¬×Ô¼ºËùÓи¸Àà * Detail description * @param none * @global none * @since 1.0 * @access private * @return void * @update date time */ function getcatagory($CatagoryID,$type=1) { $Result=$this->checkcatagory($CatagoryID); $Lft=$Result['Lft']; $Rgt=$Result['Rgt']; $SeekSQL="SELECT * FROM `".$this->tablefix."catagory` WHERE "; switch ($type) { case "1": $condition="`Lft`>$Lft AND `Rgt`<$Rgt"; break; case "2": $condition="`Lft`>=$Lft AND `Rgt`<=$Rgt"; break; case "3": $condition="`Lft`<$Lft AND `Rgt`>$Rgt"; break; case "4": $condition="`Lft`<=$Lft AND `Rgt`>=$Rgt"; break; default : $condition="`Lft`>$Lft AND `Rgt`<$Rgt"; ; } $SeekSQL.=$condition." ORDER BY `Lft` ASC"; $Sorts=$this->db->getrows($SeekSQL); return $Sorts; } // end func /** * Short description. * È¡µÃÖ±Êô¸¸Àà * Detail description * @param none * @global none * @since 1.0 * @access private * @return void * @update date time */ function getparent($CatagoryID) { $Parent=$this->getcatagory($CatagoryID,3); return $Parent; } // end func /** * Short description. * Òƶ¯Àà,Èç¹ûÀàÓÐ×ÓÀàÒ²Ò»²¢Òƶ¯ * Detail description * @param none * @global none * @since 1.0 * @access private * @return void * @update date time */ function movecatagory($SelfCatagoryID,$ParentCatagoryID) { $SelfCatagory=$this->checkcatagory($SelfCatagoryID); $NewCatagory=$this->checkcatagory($ParentCatagoryID); $SelfLft=$SelfCatagory['Lft']; $SelfRgt=$SelfCatagory['Rgt']; $Value=$SelfRgt-$SelfLft; //È¡µÃËùÓзÖÀàµÄID·½±ã¸üÐÂ×óÓÒÖµ $CatagoryIDS=$this->getcatagory($SelfCatagoryID,2); foreach($CatagoryIDS as $v){ $IDS[]=$v['CatagoryID']; } $InIDS=implode(",",$IDS); $ParentLft=$NewCatagory['Lft']; $ParentRgt=$NewCatagory['Rgt']; //print_r($InIDS); //print_r($NewCatagory); //print_r($SelfCatagory); //exit; if($ParentRgt>$SelfRgt){ $UpdateLeftSQL="UPDATE `".$this->tablefix."catagory` SET `Lft`=`Lft`-$Value-1 WHERE `Lft`>$SelfRgt AND `Rgt`<=$ParentRgt"; $UpdateRightSQL="UPDATE `".$this->tablefix."catagory` SET `Rgt`=`Rgt`-$Value-1 WHERE `Rgt`>$SelfRgt AND `Rgt`<$ParentRgt"; $TmpValue=$ParentRgt-$SelfRgt-1; $UpdateSelfSQL="UPDATE `".$this->tablefix."catagory` SET `Lft`=`Lft`+$TmpValue,`Rgt`=`Rgt`+$TmpValue WHERE `CatagoryID` IN($InIDS)"; }else{ $UpdateLeftSQL="UPDATE `".$this->tablefix."catagory` SET `Lft`=`Lft`+$Value+1 WHERE `Lft`>$ParentRgt AND `Lft`<$SelfLft"; $UpdateRightSQL="UPDATE `".$this->tablefix."catagory` SET `Rgt`=`Rgt`+$Value+1 WHERE `Rgt`>=$ParentRgt AND `Rgt`<$SelfLft"; $TmpValue=$SelfLft-$ParentRgt; $UpdateSelfSQL="UPDATE `".$this->tablefix."catagory` SET `Lft`=`Lft`-$TmpValue,`Rgt`=`Rgt`-$TmpValue WHERE `CatagoryID` IN($InIDS)"; } $this->db->query($UpdateLeftSQL); $this->db->query($UpdateRightSQL); $this->db->query($UpdateSelfSQL); //$this->referto("³É¹¦Òƶ¯Àà±ð","[removed]history.back(1)",3); return 1; } // end func /** * Short description. * * Detail description * @param none * @global none * @since 1.0 * @access private * @return void * @update date time */ function checkcatagory($CatagoryID) { //¼ì²â¸¸ÀàIDÊÇ·ñ´æÔÚ $SQL="SELECT * FROM `".$this->tablefix."catagory` WHERE `CatagoryID`='$CatagoryID' LIMIT 1"; $Result=$this->db->getrow($SQL); if(count($Result)<1){ $this->referto("¸¸ÀàID²»´æÔÚ,Çë¼ì²é","[removed]history.back(1)",3); } return $Result; } // end func /** * Short description. * * Detail description * @param none * @global none * @since 1.0 * @access private * @return array($Catagoryarray,$Deep) * @update date time */ function sort2array($CatagoryID=0) { $Output = array(); if($CatagoryID==0){ $CatagoryID=$this->getrootid(); } if(empty($CatagoryID)){ return array(); exit; } $Result = $this->db->query('SELECT Lft, Rgt FROM `'.$this->tablefix. 'catagory` WHERE `CatagoryID`='.$CatagoryID); if($Row = $this->db->fetch_array($Result)) { $Right = array(); $Query = 'SELECT * FROM `'.$this->tablefix. 'catagory` WHERE Lft BETWEEN '.$Row['Lft'].' AND '. $Row['Rgt'].' ORDER BY Lft ASC'; $Result = $this->db->query($Query); while ($Row = $this->db->fetch_array($Result)) { if (count($Right)>0) { while ($Right[count($Right)-1]<$Row['Rgt']) { array_pop($Right); } } $Output[]=array('Sort'=>$Row,'Deep'=>count($Right)); $Right[] = $Row['Rgt']; } } return $Output; } // end func /** * Short description. * * Detail description * @param none * @global none * @since 1.0 * @access private * @return void * @update date time */ function getrootid() { $Query="SELECT * FROM`".$this->tablefix."catagory` ORDER BY `Lft` ASC LIMIT 1"; $RootID=$this->db->getrow($Query); if(count($RootID)>0){ return $RootID['CatagoryID']; }else{ return 0; } } // end func /** * Short description. * * Detail description * @param none * @global none * @since 1.0 * @access private * @return void * @update date time */ function referto($msg,$url,$sec) { echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"; echo "<meta http-equiv=refresh content=$sec;URL=$url>"; if(is_array($msg)){ foreach($msg as $key=>$value){ echo $key."=>".$value."<br>"; } }else{ echo $msg; } exit; } // end func } // end class ?>
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿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¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ