Home Backend Development PHP Tutorial Two solutions to PHP Infinitus classification implementation_PHP tutorial

Two solutions to PHP Infinitus classification implementation_PHP tutorial

Jul 21, 2016 pm 03:11 PM
php Down under code Classification accomplish method unlimited of solve

Today I wrote about Infinitus classification, so I’ll post the code below. It’s not very good.

method of classify one

Copy code The code is as follows:

/*

reader: 这是自己写的无限极分类实现方法 里面的编辑方法只是对分类名进行了编辑
没有进行移动操作 小弟能力有限忘大家多多包涵啊

第一种方法:CREATE TABLE `types` (
`type_id` int(11) NOT NULL AUTO_INCREMENT,
`type_name` varchar(20) NOT NULL,
`type_p_id` varchar(64) NOT NULL DEFAULT '-',
PRIMARY KEY (`type_id`),
KEY `type_name` (`type_name`),
KEY `tname` (`type_name`)
) ENGINE=MyISAM AUTO_INCREMENT=14 DEFAULT CHARSET=utf8
注:
这里没做字段有效验证;
type_id 表示主键自增
type_name 表示分类名
type_p_id 表示分类路径 这里的分类路径是 上层父类的分类路径加上此类的主键id 用逗号隔开
*/
error_reporting(7);
header("Content:text/html;charset=utf-8");
//这里先进行操作的判断
$arr = array('list','add','del','edit','addok','edit_ok');
$act= in_array($_GET['ac'],$arr)?$_GET['ac']:$arr[0];
//连接数据库
$conn = mysql_connect("localhost","root","root")or die('数据库连接失败');
mysql_select_db("study",$conn);
mysql_query("set names utf8");
//根据分类层进行排序
$sql = "select * from types order by type_p_id";
$sql1 = mysql_query($sql);
//添加分类
if($act == "addok"){
$type_id = $_POST['type_id'];
$type_name = $_POST['type_name'];
//如果等于0表示是跟目录
if($type_id=="0"){
$sql = "insert into types set type_name = '{$type_name}'";
$res = mysql_query($sql);
$id = mysql_insert_id();
$sql = "update types set type_p_id = '$id,' where type_id=$id";
$res = mysql_query($sql);
if( mysql_affected_rows ()>0){
            echo "<script>location.href='ok.php?act=list'</script>";
        }else{
            echo "<script>alert('添加失败');</script>";
        }
    }//如果不等于0
    else{
        //根据typeid 找到 该id下的type_p_id
        $sql = "select type_p_id from `types` where type_id =  $type_id";
        $res = mysql_query($sql);
        $res = mysql_fetch_assoc($res);
        $type_id = $res['type_p_id'];

                                                                                                                                                     The executed id is then updated to mainly update type_p_id
                                                                                                                                      $ Res = mysql_query ($ SQL);
if ($ res) {
echo "& lt; script & gt; local } else { echo "& lt; script & gt; alert ('Add failure'); & lt;/script & gt;"
}
} elseif ($ activity == "add") {
?>


New category name: < br/>
Current category:



}elseif($act == "list"){
//Get the list and sort it according to the classification layer
$sql = "select * from types order by type_p_id";
$res = mysql_query( $sql);
?>

< td>id
while($arr = mysql_fetch_assoc($res)){?>


; |
                                                                                                                                                                             ;/tr>
}
?>
category namepath pathoperation
< /td>


}elseif($act == "edit"){
  $id = $_GET['type_id'];
$sql = "select *from `types` where type_id=$id ";
$res = mysql_query($sql);
echo "
";
while($arr = mysql_fetch_assoc($res)){
echo "Current name: {$arr['type_name']}"."
";
echo "New name:"."
";
echo " ";
}
echo "";
echo "
";
}elseif($act == "edit_ok"){
$name = trim($_POST['n_type_name']);
$id = $_POST['id'];
if(!empty($name)){
$sql = "update `types` set type_name='$name' where type_id=$id" ;
mysql_query($sql);
echo "<script>location.href('ok.php?act=list')</script>";
}else{
echo "<script>location.href('ok.php?act=list')</script>";
}
}elseif($act == 'del'){
// The deletion here is to delete both the current category and the current subcategory, so $id%
$id = $_GET['type_id'];
$sql="delete from `types` where type_p_id like '$id%' ";
$res = mysql_query($sql);
if($res){
echo "<script>location.href('ok.php?act=list ')</script>";
}else{
} echo "<script>alert('Deletion failed');</script>";
}
}
?>


types table:

The following is the rendering:

method of classify two

Copy code The code is as follows:

/*

reader:
这是自己写的无限极分类实现方法 里面的编辑很简单的(你们懂得。) 就没写了
没有进行移动操作 小弟能力有限忘大家多多包涵啊
第二种方法:
CREATE TABLE `types` (
`type_id` int(11) NOT NULL AUTO_INCREMENT,
`type_name` varchar(20) NOT NULL,
`type_p_id` varchar(64) NOT NULL,
PRIMARY KEY (`type_id`),
KEY `type_name` (`type_name`),
KEY `tname` (`type_name`)
) ENGINE=MyISAM AUTO_INCREMENT=14 DEFAULT CHARSET=utf8
注:
这里没做字段有效验证;
type_id 表示主键自增
type_name 表示分类名
type_p_id 表示分类路径 这里的分类路径是 上层的分类id 如果是当前分类 这个值为 0
*/
error_reporting(7);
header("Content-type:text/html;charset=utf-8");
//这里先进行操作的判断
$arr = array('list','add','del','edit','addok','edit_ok');
$act= in_array($_GET['ac'],$arr)?$_GET['ac']:$arr[0];
//连接数据库
$conn = mysql_connect("localhost","root","root")or die('数据库连接失败');
mysql_select_db("study",$conn);
mysql_query("set names utf8");

if($act=="add"){
/**
* @access public
* @param array $types array The array here needs to be passed by reference&
* @param internal $pid The upper level category id of the category it belongs to
* @param int $path the classification layer By default, it starts from 0 and adds one each time through the loop
* @return array();
*/
function getTypes(&$types=array(),$pid=0,$path=0){
$sql = "select * from `type` where type_p_id = $pid";
$res = mysql_query($sql);
while($row = mysql_fetch_assoc($res)){
$str = "";
for($i=0;$i<$path;$i++){
                                                                      = $str.$row['type_name'];
$types[] = $row;
getTypes($types,$row['type_id'],($path+1));
}
Return $types;
}
//Get the classification calling function
getTypes($types);
//Get the list and sort it according to the classification layer
$sql1 = "select * from type order by type_id";
$sqll = mysql_query($sql1);
?>


New category name:

Current category:
}elseif($act == "del"){
/***
                                                                        using                                                                       out   out out out out out out out out wanting out’’ being being being being so being so so so so so so so so so so so so so so so so to so so so so to so so so so so to so so so to so so so so so to so to so so so so so so so so so so so so to so to so to to to to to to to to to to to to To To to,*/
mysql_query("SET AUTOCOMMIT=1");//Open transaction
$type_id = $_GET['type_id '];
//Delete this category
$sqlone = "delete from `type` where type_id=$type_id";
//Delete subcategories under this category
$sqltwo = "delete from `type`where type_p_id=$type_id";
$res1 = mysql_query($sqlone);
$res2 = mysql_query($sqltwo);
if($res1 && $res2)
{
mysql_query("COMMIT");
echo "<script>location.href='two.php?act=list'</script>";
}else{
mysql_query( "ROLLBACK");
echo "<script>alert('Deletion failed');</script>";
}
}
?>



type table:

The following is the rendering

The writing is indeed not very good. I hope everyone can forgive me.

http://www.bkjia.com/PHPjc/326919.html

truehttp: //www.bkjia.com/PHPjc/326919.htmlTechArticleToday I wrote about the Infinitus classification and I posted the code below. The writing is not very good. method of classifyone Copy code The code is as follows: ?php /* reader: This is the Infinitus classification written by myself...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles