php無制限分類



<?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
 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__." <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());
}
}
?>