無限極中國有限公司 php 無限極分類

來源:互聯網
上載者:User
複製代碼 代碼如下:


/*========================================================
類名: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
參照文章 http://www.phpchina.com/12823/viewspace_4468.html
========================================================*/
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());
}
}
?>

以上就介紹了無限極中國有限公司 php 無限極分類,包括了無限極中國有限公司方面的內容,希望對PHP教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.