


The infinite classification class I wrote a few days ago_PHP tutorial
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]
I won’t explain the principle here, just send the code directly.
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.
/**
--
-- 表的结构 `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->tbname=TB_PREX.'_category';
$this->module=new module($this->tbname);
}
/**
* Add child node
* @param array $node The attributes of the child node to be added
* @param int $pid The ID of the parent node
*/
function add($node,$pid){
//Check whether the node already exists
if($node_exist=$this- >module->detail('where pid='.$pid.' and cname=''.$node['cname'].''')){
__FUNCTION__.'(): The node '.$node['cname'].' already exists! ');
//print_r($node_exist); > 'update `'.$this->tbname.'` set lft=lft+2 where lft>'.$pnode['rgt']);
$this->module->query('update `'.$this->tbname.'` set rgt=rgt+2 where rgt>='.$pnode['rgt']);
//Insert new node
$node['pid' ]=$pid;
$node['lft']=$pnode['rgt'];
$node['rgt']=$pnode['rgt']+1;
$node ['level']=$pnode['level']+1; // Add one to the level
return $this->module->add($node);
}
/**
* Delete node
* @param $cid ID of the node to be deleted
* @param $delete_childern If the node has child nodes, whether to force deletion.If the setting is not true, when there is a child node, the deletion fails and returns false
* *
*/
function delete($cid,$delete_childern=false)
{
//Get Node information
$node=$this->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 child nodes
$this->module->delete('where lft between '.$node['lft'].' and '.$node ['rgt']);
//Modify the corresponding left and right key values
$plus=$node['rgt']-$node['lft']+1;
$this-> module->query('update `'.$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; $set,'where cid='.$cid);
}
/**
* Update a node
* @param array $set update set
* @param int $cid The primary key ID of the updated node
*/
function select($cid,$deep=0)
{
['rgt'];
if(!empty($deep))$where.=' and level<'.$node['level']+$deep;
if($deep==1) {
$where.=' order by orderstyle desc'; 🎜> return $this->module- >select($where);
} get_by_cid($cid);
return $this->module->select('where lft<='.$node['lft'].' and rgt>='.$node['rgt'] .' order by lft asc');
}
/**
* Select child nodes*/
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);
}
/**
* Get the deep layer sub-node
* @param int $cid node’s primary key ID
* @param int $deep selection depth
*/
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);
}
/**
* Get node information
* @param $cid The primary key ID of the node
* @return array $node
*/
function get_by_cid($cid){
$node=$this->module->detail('where cid='.$cid);
if(!$node)$this->error(__FUNCTION__.'():获取节点'.$cid.'失败!'); ['lft']-1)/2;
}
/**
* Get the number of child nodes
* @param array $node node information
* @return num
*/
function display($cid)
{ select($cid);
foreach($nodes as $node){
echo str_repeat(' ',$node['level']-1).$node['cname']."n";
------*/
function error($msg){
die('ERROR : file '.__FILE__.' function '.$msg);
}
}
?>
http://www.bkjia.com/PHPjc/317731.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/317731.html
I wrote it a week ago, and the effect is pretty good in use. The main idea comes from: http://www.phpobject.net/b...[url=http://www.phpobject.net/blog/read.php?49][/url] I won’t explain the principle here. ...

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











You may have encountered the problem of green lines appearing on the screen of your smartphone. Even if you have never seen it, you must have seen related pictures on the Internet. So, have you ever encountered a situation where the smart watch screen turns white? On April 2, CNMO learned from foreign media that a Reddit user shared a picture on the social platform, showing the screen of the Samsung Watch series smart watches turning white. The user wrote: "I was charging when I left, and when I came back, it was like this. I tried to restart, but the screen was still like this during the restart process." Samsung Watch smart watch screen turned white. The Reddit user did not specify the smart watch. Specific model. However, judging from the picture, it should be Samsung Watch5. Previously, another Reddit user also reported

foobar2000 is a software that can listen to music resources at any time. It brings you all kinds of music with lossless sound quality. The enhanced version of the music player allows you to get a more comprehensive and comfortable music experience. Its design concept is to play the advanced audio on the computer The device is transplanted to mobile phones to provide a more convenient and efficient music playback experience. The interface design is simple, clear and easy to use. It adopts a minimalist design style without too many decorations and cumbersome operations to get started quickly. It also supports a variety of skins and Theme, personalize settings according to your own preferences, and create an exclusive music player that supports the playback of multiple audio formats. It also supports the audio gain function to adjust the volume according to your own hearing conditions to avoid hearing damage caused by excessive volume. Next, let me help you

CrystalDiskMark is a small HDD benchmark tool for hard drives that quickly measures sequential and random read/write speeds. Next, let the editor introduce CrystalDiskMark to you and how to use crystaldiskmark~ 1. Introduction to CrystalDiskMark CrystalDiskMark is a widely used disk performance testing tool used to evaluate the read and write speed and performance of mechanical hard drives and solid-state drives (SSD). Random I/O performance. It is a free Windows application and provides a user-friendly interface and various test modes to evaluate different aspects of hard drive performance and is widely used in hardware reviews

MetaMask (also called Little Fox Wallet in Chinese) is a free and well-received encryption wallet software. Currently, BTCC supports binding to the MetaMask wallet. After binding, you can use the MetaMask wallet to quickly log in, store value, buy coins, etc., and you can also get 20 USDT trial bonus for the first time binding. In the BTCCMetaMask wallet tutorial, we will introduce in detail how to register and use MetaMask, and how to bind and use the Little Fox wallet in BTCC. What is MetaMask wallet? With over 30 million users, MetaMask Little Fox Wallet is one of the most popular cryptocurrency wallets today. It is free to use and can be installed on the network as an extension

NetEase Mailbox, as an email address widely used by Chinese netizens, has always won the trust of users with its stable and efficient services. NetEase Mailbox Master is an email software specially created for mobile phone users. It greatly simplifies the process of sending and receiving emails and makes our email processing more convenient. So how to use NetEase Mailbox Master, and what specific functions it has. Below, the editor of this site will give you a detailed introduction, hoping to help you! First, you can search and download the NetEase Mailbox Master app in the mobile app store. Search for "NetEase Mailbox Master" in App Store or Baidu Mobile Assistant, and then follow the prompts to install it. After the download and installation is completed, we open the NetEase email account and log in. The login interface is as shown below

Cloud storage has become an indispensable part of our daily life and work nowadays. As one of the leading cloud storage services in China, Baidu Netdisk has won the favor of a large number of users with its powerful storage functions, efficient transmission speed and convenient operation experience. And whether you want to back up important files, share information, watch videos online, or listen to music, Baidu Cloud Disk can meet your needs. However, many users may not understand the specific use method of Baidu Netdisk app, so this tutorial will introduce in detail how to use Baidu Netdisk app. Users who are still confused can follow this article to learn more. ! How to use Baidu Cloud Network Disk: 1. Installation First, when downloading and installing Baidu Cloud software, please select the custom installation option.

Speaking of ASSASSIN, I believe players will definitely think of the master assassins in "Assassin's Creed". They are not only skilled, but also have the creed of "devoting themselves to the darkness and serving the light". The ASSASSIN series of flagship air-cooled radiators from the appliance brand DeepCool coincide with each other. Recently, the latest product of this series, ASSASSIN4S, has been launched. "Assassin in Suit, Advanced" brings a new air-cooling experience to advanced players. The appearance is full of details. The Assassin 4S radiator adopts a double tower structure + a single fan built-in design. The outside is covered with a cube-shaped fairing, which has a strong overall sense. It is available in white and black colors to meet different colors. Tie

A large model that can automatically analyze the content of PDFs, web pages, posters, and Excel charts is not too convenient for workers. The InternLM-XComposer2-4KHD (abbreviated as IXC2-4KHD) model proposed by Shanghai AILab, the Chinese University of Hong Kong and other research institutions makes this a reality. Compared with other multi-modal large models that have a resolution limit of no more than 1500x1500, this work increases the maximum input image of multi-modal large models to more than 4K (3840x1600) resolution, and supports any aspect ratio and 336 pixels to 4K Dynamic resolution changes. Three days after its release, the model topped the HuggingFace visual question answering model popularity list. Easy to handle
