The following code is the SQL code that creates the appropriate database:
Copy Code code as follows:
//////////////
Database design of infinite classification and its examples
//////////////
mysql> CREATE DATABASE Db_kind;
Query OK, 1 row affected
mysql> use Db_kind;
Database changed
Mysql> CREATE TABLE Tb_kind (
-> ID int NOT NULL auto_increment primary key,
-> PID int,
-> path varchar (200)
->);
Query OK, 0 rows affected
mysql> INSERT INTO tb_kind values (NULL, "News", 0,0);
Query OK, 1 row affected
mysql> INSERT INTO tb_kind values (null, "video", 0,0);
Query OK, 1 row affected
mysql> INSERT INTO tb_kind values (null, "Picture", 0,0);
Query OK, 1 row affected
mysql> INSERT INTO tb_kind values (null, "blog", 0,0);
Query OK, 1 row affected
mysql> INSERT INTO tb_kind values (NULL, "Sports News", 1, "0-1");
Query OK, 1 row affected
mysql> INSERT INTO tb_kind values (NULL, "Entertainment News", 1, "0-1");
Query OK, 1 row affected
mysql> INSERT INTO tb_kind values (NULL, "Financial News", 1, "0-1");
Query OK, 1 row affected
Mysql> select * from Db_kind;
ERROR 1146:table ' db_kind.db_kind ' doesnot exist
Mysql> SELECT * from TB
_kind;
+----+----------+-----+------+
| ID | PName | PID | Path |
+----+----------+-----+------+
| 1 | News | 0 | 0 |
| 2 | Video | 0 | 0 |
| 3 | Pictures | 0 | 0 |
| 4 | Blog | 0 | 0 |
| 5 | Sports News | 1 | 0-1 |
| 6 | Entertainment News | 1 | 0-1 |
| 7 | Financial News | 1 | 0-1 |
+----+----------+-----+------+
7 Rows in Set
mysql> INSERT INTO tb_kind values (NULL, "Basketball News", 5, "0-1-5");
Query OK, 1 row affected
mysql> INSERT INTO tb_kind values (NULL, "Football News", 5, "0-1-5");
Query OK, 1 row affected
Mysql> select * from Tb_kind;
+----+----------+-----+-------+
| ID | PName | PID | Path |
+----+----------+-----+-------+
| 1 | News | 0 | 0 |
| 2 | Video | 0 | 0 |
| 3 | Pictures | 0 | 0 |
| 4 | Blog | 0 | 0 |
| 5 | Sports News | 1 | 0-1 |
| 6 | Entertainment News | 1 | 0-1 |
| 9 2 Financial News | 1 | 0-1 |
| 8 | Basketball News | 5 | 0-1-5 |
| 9 | Football News | 5 | 0-1-5 |
+----+----------+-----+-------+
9 Rows in Set
mysql> INSERT INTO tb_kind values (null, "NBA", 8, "0-1-5-8");
Query OK, 1 row affected
mysql> INSERT INTO tb_kind values (null, "CBA", 8, "0-1-5-8");
Query OK, 1 row affected
Mysql> select * from Tb_kind;
+----+----------+-----+---------+
| ID | PName | PID | Path |
+----+----------+-----+---------+
| 1 | News | 0 | 0 |
| 2 | Video | 0 | 0 |
| 3 | Pictures | 0 | 0 |
| 4 | Blog | 0 | 0 |
| 5 | Sports News | 1 | 0-1 |
| 6 | Entertainment News | 1 | 0-1 |
| 7 | Financial News | 1 | 0-1 |
| 8 | Basketball News | 5 | 0-1-5 |
| 9 | Football News | 5 | 0-1-5 |
| 10 | NBA | 8 | 0-1-5-8 |
| 11 | CBA | 8 | 0-1-5-8 |
+----+----------+-----+---------+
Rows in Set
Mysql> Select concat (Path, "-", id) from Tb_kind;
+---------------------+
| Concat (Path, "-", id) |
+---------------------+
| 0-1 |
| 0-2 |
| 0-3 |
| 0-4 |
| 0-1-5 |
| 0-1-6 |
| 0-1-7 |
| 0-1-5-8 |
| 0-1-5-9 |
| 0-1-5-8-10 |
| 0-1-5-8-11 |
+---------------------+
Rows in Set
Mysql> Select concat (Path, "-", id) from Tb_kind;
+---------------------+
| Concat (Path, "-", id) |
+---------------------+
| 0-1 |
| 0-2 |
| 0-3 |
| 0-4 |
| 0-1-5 |
| 0-1-6 |
| 0-1-7 |
| 0-1-5-8 |
| 0-1-5-9 |
| 0-1-5-8-10 |
| 0-1-5-8-11 |
+---------------------+
Rows in Set
Mysql> Select concat (Path, "-", id) as ABS from Tb_kind order by Abs.path;
ERROR 1054:unknown column ' Abs.path ' in ' order clause '
Mysql> Select concat (Path, "-", id) as ABS from Tb_kind ORDER BY ABS
+------------+
| ABS |
+------------+
| 0-1 |
| 0-1-5 |
| 0-1-5-8 |
| 0-1-5-8-10 |
| 0-1-5-8-11 |
| 0-1-5-9 |
| 0-1-6 |
| 0-1-7 |
| 0-2 |
| 0-3 |
| 0-4 |
+------------+
Rows in Set
Mysql> Select concat (Path, "-", id) as,id,name,path abs from Tb_kind;
Error 1064:you have an error in your SQL syntax; Check the manual that corresponds to your MySQL server version for the right syntax to use near ' Id,name,path abs from Tb_ Kind ORDER by ABS ' at line 1
Mysql> Select concat (Path, "-", id) as ABS,
Id,pname,path ABS from Tb_kind ORDER by ABS;
+------------+----+----------+---------+
| ABS | ID | PName | ABS |
+------------+----+----------+---------+
| 0-1 | 1 | News | 0 |
| 0-1-5 | 5 | Sports News | 0-1 |
| 0-1-5-8 | 8 | Basketball News | 0-1-5 |
| 0-1-5-8-10 | 10 | NBA | 0-1-5-8 |
| 0-1-5-8-11 | 11 | CBA | 0-1-5-8 |
| 0-1-5-9 | 9 | Football News | 0-1-5 |
| 0-1-6 | 6 | Entertainment News | 0-1 |
| 0-1-7 | 9 2 Financial News | 0-1 |
| 0-2 | 2 | Video | 0 |
| 0-3 | 3 | Pictures | 0 |
| 0-4 | 4 | Blog | 0 |
+------------+----+----------+---------+
Rows in Set
Mysql>
The following are the PHP source files:
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> Untitled Document </title>
<body>
<!--display Results
News
Sports News
Basketball News
Nba
Cba
Football News
Entertainment News
Financial News
Video
Image
Blog
-->
?
$conn =mysql_connect ("localhost", "root", "root");
mysql_select_db ("Db_kind");
mysql_query ("Set names UTF8");
$sql = "Select concat (Path, '-', id) as Abspath,id,pname,path from Tb_kind order by Abspath";
$rs =mysql_query ($sql);
while ($result =mysql_fetch_assoc ($rs)) {
$num =count (Explode ("-", $result [path])-1;
$new _str=str_repeat ("---", $num);
Echo $new _str. $result [PName];
echo "<br>";
}
$str =str_repeat ("=", 10);
Echo $str;
$num =count (Explode ("-", "0-1-5-8"))-1;
Echo $num;
?>
</body>
The above code in fact, the middle of the input effect of space is very good, please local test. Typographical confusion caused by editor problems.