栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

php 无限极分类

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

php 无限极分类

复制代码 代码如下:

class catalog{
var $config;
var $catalog_dbname;
var $links;
private function connect(){
$this->links = mysql_connect($this->config['host'],$this->config['user'],$this->config['pass']) or die("错误: 第".__LINE__."行
".mysql_error());
mysql_select_db($this->config['dbname'],$this->links);
mysql_query("SET NAMES gb2312");
}
function catalog_show($uid = 0){
$this->connect();
$sql = "Select * FROM ".$this->catalog_dbname. "
Where catalog_uid = ". $uid ."
orDER BY catalog_id ";
$result = mysql_query($sql,$this->links) or die("错误: 第".__LINE__."行
".mysql_error());
if(mysql_num_rows($result) > 0){
while ($row = mysql_fetch_assoc($result)){  
if($this->sun_catalog($row['catalog_id'])){//判断有没有子分类
$cata_img = "";
}else{
$cata_img = "";
}
$path = explode(":",$row['catalog_path_number']);
if(count($path) > 1){
for($i=1;$i$path_img .= "";
}
}
echo $path_img.$cata_img;
echo "";
echo $row['catalog_name']."
";
$path_img = "";
if($this->sun_catalog($row['catalog_id'])){  
$hidden_div = "style='display:none'";  
echo "";  
$this->catalog_show($row['catalog_id']);
echo "";
}  
}
}  
}
private function sun_catalog($uid){//判断是否有子分类
$sql = "Select * FROM ".$this->catalog_dbname. "
Where catalog_uid = ". $uid ."
orDER BY catalog_id ";
$result = mysql_query($sql,$this->links) or die("错误: 第".__LINE__."行
".mysql_error());
if(mysql_num_rows($result) > 0){
return true;
}else{
return false;
}
}
function catalog_add($uid,$name){
//获取父id的亲缘树
$this->connect();
$sql = "Select * FROM ".$this->catalog_dbname."
Where catalog_id = '".$uid."'";
$result = mysql_query($sql,$this->links)
or die("错误: 第".__LINE__."行
".mysql_error());
$row = mysql_fetch_assoc($result);
$fid_path_number = $row['catalog_path_number'];//id的数字亲缘树
$fid_path_char = $row['catalog_path_char'];//id的字符亲缘树
//插入数据 先插入行->再找到最新插入的id, 在依据这个id进行修改
$sql = "Insert INTO ".$this->catalog_dbname."(catalog_uid,catalog_name)
VALUES(".$uid.",'".$name."')";
$result = mysql_query($sql,$this->links)
or die("错误: 第".__LINE__."行
".mysql_error());
$catalog_id = mysql_insert_id();//获取自己的id
$catalog_path_number = $fid_path_number.":".$catalog_id;//得到自己的数字亲缘数
$catalog_path_char = $fid_path_char.":".$name;//得到自己的字符亲缘数
$sql = "Update '".$this->catalog_dbname."'
SET
catalog_path_number = '".$catalog_path_number."',
catalog_path_char = '".$catalog_path_char."'
Where
catalog_id = ".$catalog_id;  
mysql_query($sql,$this->links)
or die("错误: 第".__LINE__."行
".mysql_error());  
}
function catalog_del($id){
$this->connect();
$sql = "Delete FROM ".$this->catalog_dbname."
Where catalog_id = ".$id;
mysql_query($sql,$this->links)
or die("错误: 第".__LINE__."行
".mysql_error());
}
function catalog_set($id,$name){
$this->connect();
$sql = "Update ".$this->catalog_dbname."
SET
catalog_name = '".$name."'
Where
catalog_id = ".$id;  
mysql_query($sql,$this->links)
or die("错误: 第".__LINE__."行
".mysql_error());
}
}
?>
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/53308.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号