Infinite Pole China limited php infinite pole classification

Source: Internet
Author: User
Copy CodeThe code is as follows:


/*========================================================
Class Name: Catalog
Function: Unlimited Grading class
Method:
Tree-type Display classification
Catalog_show ($id)//parameter $id recursive invocation
Process: Find parent category 0 All root categories-always recursively get all categories and show
Add Category
Catalog_add ($uid, $name)//$uid Parent ID//$name category name
Process: According to $uid, add a new sub-ID under this ID
Delete Category
Catalog_del ($UID)//parameter $uid number of categories to delete
Modify classification
Catalog_set ($id, $name)//parameter $id the category//parameter to be modified $name the new category name
Variable:
$config//Database information, Host,user,pass,dbname
$catalog _dbname//Classification database name
Database:
CATALOG_ID//classification of natural serial numbers
CATALOG_UID//Classification of the parent category
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: Category 1.1.1
Refer to Article 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 ("Error: section". __line__. " Yes
". 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: section". __line__. " Yes
". 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 sub-classifications
$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) {//To determine if there are sub-categories
$sql = "SELECT * from". $this->catalog_dbname. "
Where Catalog_uid = ". $uid. "
OrDER by catalog_id ";
$result = mysql_query ($sql, $this->links) or Die ("Error: section". __line__. " Yes
". Mysql_error ());
if (mysql_num_rows ($result) > 0) {
return true;
}else{
return false;
}
}
function Catalog_add ($uid, $name) {
Gets 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: section". __line__. Yes
". Mysql_error ());
$row = Mysql_fetch_assoc ($result);
$fid _path_number = $row The number tree of the [' Catalog_path_number '];//id
$fid _path_char = character affinity tree for $row [' Catalog_path_char '];//id
Insert data Insert line First, and then find the latest inserted ID, in accordance with this ID to modify
$sql = "Insert into". $this->catalog_dbname. " (Catalog_uid,catalog_name)
VALUES (". $uid.", ' ". $name." ') ";
$result = mysql_query ($sql, $this->links)
Or Die ("Error: section". __line__. Yes
". Mysql_error ());
$catalog _id = mysql_insert_id ();//Get your own ID
$catalog _path_number = $fid _path_number. ":" $catalog _id;//get the number of their number relatives
$catalog _path_char = $fid _path_char. ":" $NAME;//Get your own character affinity number
$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: section". __line__. Yes
". 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: section". __line__. Yes
". 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: section". __line__. Yes
". Mysql_error ());
}
}
?>

The above introduces the infinite Pole China limited PHP unlimited pole classification, including the Infinite pole China limited content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.