Home > Backend Development > PHP Tutorial > Opinions on promoting the reform of public institutions by classification. The infinite classification category I wrote a few days ago

Opinions on promoting the reform of public institutions by classification. The infinite classification category I wrote a few days ago

WBOY
Release: 2016-07-29 08:36:17
Original
900 people have browsed it

I wrote this a week ago, and it works pretty well in use.
The main idea comes from: http://www.phpobject.net/b...[url=http://www.phpobject.net/blog/read.php?49][/url]
Not much explanation here The principle is clear, just send the code.
PS: This code cannot be used directly and must be combined with some of my other library classes. It should be said that thought is the most important. Here we mainly provide a classification idea.

Copy the code The code is as follows:


/** 
--  
-- 表的结构 `daxue8_category` 
--  
CREATE TABLE `daxue8_category` ( 
  `cid` smallint(6) NOT NULL auto_increment, 
  `pid` smallint(6) NOT NULL default '0', 
  `level` smallint(6) NOT NULL default '0', 
  `cname` char(64) NOT NULL default '', 
  `lft` smallint(6) NOT NULL default '0', 
  `rgt` smallint(6) NOT NULL default '0', 
  `uid` mediumint(8) NOT NULL default '0', 
  `username` char(32) NOT NULL default '', 
  `ctime` int(10) NOT NULL default '0', 
  `cstate` tinyint(1) NOT NULL default '0', 
  `gnum` mediumint(8) NOT NULL default '0', 
  `orderstyle` smallint(3) NOT NULL default '0', 
  PRIMARY KEY  (`cid`) 
) TYPE=MyISAM AUTO_INCREMENT=2 ; 
--  
-- 导出表中的数据 `daxue8_category` 
--  
INSERT INTO `daxue8_category` VALUES (1, 0, 1, 'root', 1, 2, 0, '管理员', 1163608814, 1, 0, 0); 
*/
class category
{
var $module;
var $tbname;
function category()
$this-& gt;tbname=TB_PREX.'_category';
          $this->module=new module($this->tbname);                                                                                                                                                                               
          if($node_exist=$this->module->detail('where pid='.$pid.' and cname=''.$node['cname'].''')){                                            $this->error(__FUNCTION__.'(): The node '.$node['cname'].' already exists!');
          //print_r($node_exist);
                                                                           ” ” ” ” ” ;
} 获 // Get the parent node information
$ pNode = $ this- & gt; get_by_cid ($ pid);
// update other nodes
$ this- & gt; module- & gt; query ('update `'. $ This ->tbname.'` set lft=lft+2 where lft>'.$pnode['rgt']); .'` set rgt = rgt+2 where rgt & gt; = '. $ PNode [' rgt ']);
// Insert new nodes
$ node [' pid '] = $ pid; =$pnode['rgt'];
                                                          using using using  -                                                                       using using   using using                 through Add u Return $ this-& gt; module-& gt; add ($ node);
}
/**
*Delete node
*@Param $ CID to delete the ID
*@param $ delete_childern If there are child nodes, whether to force deletion.If set to true, when there is a child node, deletion fails and returns false
                                                                                                                                                        ‐ > ;get_by_cid($cid);
If(($this->child_num($node)>0)&&(!$delete_childern))$this->error(__FUNCTION__.'(): This node has child nodes !'); // Delete the node and all its sub-nodes
$ this- & gt; module- & gt; delete (' where lft beteen '. ]);
                                                  using using use using using using                          ‐           ‐                          .$this->tbname.'` set lft=lft-'.$plus.' where lft>'.$node['rgt']);
           $this->module->query('update ` '.$this->tbname.'` set rgt=rgt-'.$plus.' where rgt>'.$node['rgt']);
        return true; /
Function Update ($ set, $ cid) {
Return $ this- & gt; module-& gt; update ($ set, 'where cid ='. $ Cid);
/**
           * Update a node                                                                                                              */
function select($cid,$deep=0)
{ ].' and '.$node['rgt'];
if(!empty($deep))$where.=' and level<'.$node['level']+$deep;
if($deep ==1){
                                                                   return );
}
/**及*Select nodes and their sub -nodes
*@Param Int $ CID Node ID
*@Param Int $ Deep Select depth
*/
function get_parent($cid)
{
gt;select( 'where lft<='.$node['lft'].' and rgt>='.$node['rgt'].' order by lft asc');

    /**点*Select sub -nodes 选*@Param int $ CID node, the primary key ID
*@param int $ deep, select depth
*/ 
    function get_children($pid,$deep=0){ 
        //获取节点信息 
        $pnode=$this->get_by_cid($pid); 
        $where='where lft>'.$pnode['lft'].' and rgt<'.$pnode['rgt']; 
        if(!empty($deep))$where.=' and level<='.($pnode['level']+$deep); 
        if($deep==1){ 
            $where.=' order by orderstyle desc'; 
        }else{ 
            $where.=' order by lft asc';             
        } 
        return $this->module->select($where); 
    } 
    /**
                                                                                                                                            ’*/ 
    function get_level_children($pid,$deep){ 
        //获取节点信息 
        $pnode=$this->get_by_cid($pid); 
        $where='where lft>'.$pnode['lft'].' and rgt<'.$pnode['rgt']; 
        $where.=' and level='.($pnode['level']+$deep); 
        $where.=' order by orderstyle desc'; 
        return $this->module->select($where); 
    } 
    /**
                                                                                                      using using using using using                    out way off ’s     ‐   off ‐ ‐ ‐ ‐ ‐ ‐
                                           */ 
    function get_by_cid($cid){ 
        $node=$this->module->detail('where cid='.$cid); 
        if(!$node)$this->error(__FUNCTION__.'():获取节点'.$cid.'失败!'); T Return $ Node;
}
/**
       * Get the number of child nodes                                                                                                             */
Function Child_num ($ Node) {
Return ($ node [' rgt ']-$ node [' lft ']/2 ;
}
/**次*Display classification according to the level
@Param Int $ CID Node ID
*@output
*/
function display($cid)
{
$nodes=$this->select($cid);
foreach($nodes as $node){
                                                                                                                                                                                                                                                                                 ( ' ',$node['level']-1).$node['cname']."n";
                                                                                                                                                 --------------------------*/
function error($msg){
die('ERROR : file '.__FILE__.' function ' .$msg);
}
}
?>


The above introduces the opinions on classifying and promoting the reform of public institutions. The infinite classification category I wrote a few days ago includes the opinions on classifying and promoting the reform of public institutions. I hope it will be helpful to friends who are interested in PHP tutorials.


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template