国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

PHP編程之PHP無限極分類

2024-05-04 21:52:27
字體:
來源:轉載
供稿:網友

php無限極分類
CODE=PHP]
至于添加刪除之類的功能我就不多寫了!仔細看看就知道這么用了.
難的是顯示方面
希望高手擴展一下!
QUOTE:
這是類
<?php
/*========================================================
類名:catalog
功能:無限分級類
方法:
樹形顯示分類
catalog_show(id) //參數id 遞歸調用
流程:找到父分類為0所有根分類-> 一直遞歸取得所有分類并顯示
添加分類
catalog_add(uid,name) //uid 父id //name 分類名
流程:依據uid,在此id下添加一個新子id
刪除分類
catalog_del(uid)//參數 uid 數要刪除的分類
修改分類
catalog_set(id,name) //參數 id 要修改的分類 //參數 name 新的分類名
變量:
config //數據庫信息-> host,user,pass,dbname
catalog_dbname //分類數據庫名
數據庫:

以下為引用的內容:

catalog_id //分類的自然序號
catalog_uid //分類的父分類
catalog_name //分類名
catalog_path_number //親緣樹數字形式 0:1:2
catalog_path_char //親緣樹字符形式 分類1:分類1.1:分類1.1.1

========================================================*/
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__."行<br>".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__."行<br>".mysql_error());
if(mysql_num_rows(result) > 0){
while (row = mysql_fetch_assoc(result)){
if(this->sun_catalog(row['catalog_id'])){//判斷有沒有子分類
cata_img = "<img id = 'img".row['catalog_id']."' src='./img/last_node.jpg' ōnclick='click_catalog(".row['catalog_id'].")'/>";
}else{
cata_img = "<img src='./img/sp.jpg'/>";
}
path = explode(":",row['catalog_path_number']);
if(count(path) > 1){
for(i=1;i<count(path);i ){
path_img .= "<img src='./img/sp.jpg'/>";
}
}
echo path_img.cata_img;
echo "<a class='menu' href = 'javascrīpt:send_id(".row['catalog_id'].")'>";
echo row['catalog_name']."</a><br>";
path_img = "";
if(this->sun_catalog(row['catalog_id'])){
hidden_div = "style='display:none'";
echo "<div id = 'div".row['catalog_id']."' ".hidden_div.">";
this->catalog_show(row['catalog_id']);
echo "</div>";
}
}
}
}
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__."行<br>".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__."行<br>".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__."行<br>".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__."行<br>".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__."行<br>".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__."行<br>".mysql_error());
}
}
?>
[/CODE]

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宜兰市| 秦皇岛市| 闽清县| 慈溪市| 城市| 丹凤县| 安宁市| 兴山县| 台湾省| 盐亭县| 蒲江县| 红河县| 阳春市| 岱山县| 巢湖市| 奇台县| 南溪县| 赞皇县| 墨竹工卡县| 塔城市| 夏邑县| 桃园县| 兴化市| 都江堰市| 清水河县| 凌源市| 图们市| 甘谷县| 山东省| 沅江市| 牟定县| 南部县| 陈巴尔虎旗| 丰都县| 长汀县| 防城港市| 马龙县| 秦皇岛市| 闸北区| 长子县| 如东县|