This is the class
<?php
/*========================================================
Class Name: Catalog
Function: Infinite Rating class
Method:
Tree Display category
Catalog_show ($id)//parameter $id recursive call
Process: Find the parent category for 0 all root categories-> have been recursively obtained all categories and displayed
Add a Category
Catalog_add ($uid, $name)//$uid Parent ID//$name category name
Process: Add a new child ID under this ID according to $uid
Delete Category
Catalog_del ($UID)//parameter $uid number of categories to delete
Modify Categories
Catalog_set ($id, $name)//Parameters $id the classification//parameter to be modified $name the new category name
Variable:
$config//DatabaseInformation-> Host,user,pass,dbname
$catalog _dbname//Classification database name
Database:
CATALOG_ID//Classification of natural serial number
Parent classification of CATALOG_UID//categories
Catalog_name//Category name
Catalog_path_number//Kinship tree Digital form 0:1:2
Catalog_path_char//kinship tree Character form Category 1: Category 1.1: Classification 1.1.1
Reference article [Url]http://www.111cn.net/12823/viewspace_4468.html[/url]
========================================================*/
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 (Error: __line__. " 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 (Error: page. __line__.) Line <br> ". Mysql_error ());
if (mysql_num_rows ($result) > 0) {
while ($row = Mysql_fetch_assoc ($result)) {
if ($this->sun_catalog ($row [' catalog_id '])) {//To determine if there are subcategories
$cata _img = " ";
}else{
$cata _img = "}
$path = Explode (":", $row [' Catalog_path_number ']);
if (count ($path) > 1) {
for ($i =1; $i <count ($path); $i + +) {
$path _img. = "}
}
echo $path _img. $cata _img;
echo "<a class= ' menu ' href = ' javascript: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) {//To determine whether there are subcategories
$sql = "SELECT * from". $this->catalog_dbname. "
WHERE Catalog_uid = ". $uid. "
ORDER by catalog_id ";
$result = mysql_query ($sql, $this->links) or Die (Error: page. __line__.) Line <br> ". Mysql_error ());
if (mysql_num_rows ($result) > 0) {
return true;
}else{
return false;
}
}
function Catalog_add ($uid, $name) {
Get the parent ID's affinity tree
$this->connect ();
$sql = "SELECT * from". $this->catalog_dbname. "
WHERE catalog_id = ' ". $uid." ' ";
$result = mysql_query ($sql, $this->links)
Or Die (Error:. __line__.) Line <br> ". Mysql_error ());
$row = Mysql_fetch_assoc ($result);
$fid _path_number = $row [' catalog_path_number '];//id digital affinity Tree
$fid _path_char = $row [' Catalog_path_char '];//id character affinity tree
Insert data first insert row-> and then find the most recently inserted ID, modified by this ID
$sql = "INSERT into". $this->catalog_dbname. " (Catalog_uid,catalog_name)
VALUES (". $uid.", ' ". $name.") ";
$result = mysql_query ($sql, $this->links)
Or Die (Error:. __line__.) Line <br> ". Mysql_error ());
$catalog _id = mysql_insert_id ();//Get own ID
$catalog _path_number = $fid _path_number. ":". $catalog _id;//get their number of relatives
$catalog _path_char = $fid _path_char. ":". $name//Get your own number of character relatives
$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 (Error:. __line__.) 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 (Error:. __line__.) 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 (Error:. __line__.) Line <br> ". Mysql_error ());
}
}
?>