完整的新闻无限级分类代码,可添加,删除,移动,修改
// 连接数据库教程
$link = mysql教程_connect('localhost','root','密码') or die(mysql_error());
mysql_select_db('sortclass',$link);
mysql_query("设置名称'gbk'");
//无限分类类库
类排序类{var $data = array();
var $child = array(-1=>array());
var $layer = array(-1=>-1);
var $parent = array();
var $link;
var $表;
函数 sortclass($link, $table){
$this->setnode(0, -1, '顶极节点');
$this->link = $link;
$这个->表= $表;
$节点=数组();
$results = mysql_query('select * from '.$this->table.'',$this->link);
while($node = mysql_fetch_assoc($results)){
$this->setnode($node['cid'],$node['pid'],$node['cname']);
}
}
函数 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];}
函数 getparents ($id){
while ($this->parent[$id] != -1){
$id = $parent[$this->层[$id]] = $this->parent[$id];
}
ksort($父级);
重置($父级);
返回$父级;
}
function getchild ($id){return $this->child[$id];}
函数 getchilds ($id = 0){
$child = 数组($id);
$this->getlist($child, $id);
返回 $child;
}
函数addnode($name,$pid){
mysql_query("插入$this->表(`pid`,`cname`)值('$pid','$name')",$this->link);
}
函数 modnode($cid, $newname){
mysql_query("更新 $this->table set `cname`='$newname' where `cid` = $cid",$this->link);
}
函数 delnode($cid){
$allchilds = $this->getchilds($cid);
$sql ='';
if(空($allchilds)){
$sql = "从 $this->表中删除`cid` = $cid";
}其他{
$sql = '从'.$this->表中删除。'其中 `cid` in ('.implode(',',$allchilds).','.$cid.')';
}
mysql_query($sql,$this->link);
}
函数 movenode($cid, $topid){
mysql_query("更新 $this->table set `pid`=$topid where `cid` = $cid", $this->link);
}
}
//函数
函数返回(){
echo '';
出口;
}
//选择生成
函数 makeselect($array,$formname){
全局$树;
$select = '';
}
$tree = new sortclass($link,'`class`');
$op = !empty($_post['op']) ? $_post['op'] : $_get['op'];
if(!empty($op)){if($op=='add'){
$tree->addnode($_post['cname'],$_post['pid']);
后退();
}if($op=='mod'){
$tree->modnode($_post['cid'],$_post['cname']);
后退();
}if($op=='del'){
$tree->delnode($_get['cid']);
后退();
}if($op=='移动'){
$tree->movenode($_post['who'],$_post['to']);
后退();
}
}
$category = $tree->getchilds();
?>
顶极节点 del 编辑
|- 1级分类删除 编辑
|- 1级分类删除编辑
|- 1级分类删除编辑
|- |- 2 级分类删除编辑
|- |- |- 3 级分类删除
|- |- |-|- 4 级分类删除
|- 1级分类删除编辑

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

session_start()iscucialinphpformanagingusersessions.1)ItInitiateSanewsessionifnoneexists,2)resumesanexistingsessions,and3)setsasesessionCookieforContinuityActinuityAccontinuityAcconActInityAcconActInityAcconAccRequests,EnablingApplicationsApplicationsLikeUseAppericationLikeUseAthenticationalticationaltication and PersersonalizedContentent。

在MySQL中,添加字段使用ALTERTABLEtable_nameADDCOLUMNnew_columnVARCHAR(255)AFTERexisting_column,删除字段使用ALTERTABLEtable_nameDROPCOLUMNcolumn_to_drop。添加字段时,需指定位置以优化查询性能和数据结构;删除字段前需确认操作不可逆;使用在线DDL、备份数据、测试环境和低负载时间段修改表结构是性能优化和最佳实践。

MySQL函数可用于数据处理和计算。1.基本用法包括字符串处理、日期计算和数学运算。2.高级用法涉及结合多个函数实现复杂操作。3.性能优化需避免在WHERE子句中使用函数,并使用GROUPBY和临时表。

MySQL批量插入数据的高效方法包括:1.使用INSERTINTO...VALUES语法,2.利用LOADDATAINFILE命令,3.使用事务处理,4.调整批量大小,5.禁用索引,6.使用INSERTIGNORE或INSERT...ONDUPLICATEKEYUPDATE,这些方法能显着提升数据库操作效率。

Composer是PHP的依赖管理工具,通过composer.json文件管理项目依赖。1)解析composer.json获取依赖信息;2)解析依赖关系形成依赖树;3)从Packagist下载并安装依赖到vendor目录;4)生成composer.lock文件锁定依赖版本,确保团队一致性和项目可维护性。

MySQL被广泛应用于各种项目中的原因包括:1.高性能与可扩展性,支持多种存储引擎;2.易于使用和维护,配置简单且工具丰富;3.丰富的生态系统,吸引大量社区和第三方工具支持;4.跨平台支持,适用于多种操作系统。

使用EXPLAIN命令可以分析MySQL查询的执行计划。1.EXPLAIN命令显示查询的执行计划,帮助找出性能瓶颈。2.执行计划包括id、select_type、table、type、possible_keys、key、key_len、ref、rows和Extra等字段。3.根据执行计划,可以通过添加索引、避免全表扫描、优化JOIN操作和使用覆盖索引来优化查询。

在MySQL中配置字符集和排序规则的方法包括:1.设置服务器级别的字符集和排序规则:SETNAMES'utf8';SETCHARACTERSETutf8;SETCOLLATION_CONNECTION='utf8_general_ci';2.创建使用特定字符集和排序规则的数据库:CREATEDATABASEexample_dbCHARACTERSETutf8COLLATEutf8_general_ci;3.创建表时指定字符集和排序规则:CREATETABLEexample_table(idINT
