比较的简単で実用的なPHP无限分类のソースコードを共有します。
6210 ワード
下のコードは該当データベースのsqlコードを作成します。下のファイルはphpソースです。
//////////////
//////
//////////////
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," ",0,0);
Query OK, 1 row affected
mysql> insert into tb_kind values(null," ",0,0);
Query OK, 1 row affected
mysql> insert into tb_kind values(null," ",0,0);
Query OK, 1 row affected
mysql> insert into tb_kind values(null," ",0,0);
Query OK, 1 row affected
mysql> insert into tb_kind values(null," ",1,"0-1");
Query OK, 1 row affected
mysql> insert into tb_kind values(null," ",1,"0-1");
Query OK, 1 row affected
mysql> insert into tb_kind values(null," ",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 | | 0 | 0 |
| 2 | | 0 | 0 |
| 3 | | 0 | 0 |
| 4 | | 0 | 0 |
| 5 | | 1 | 0-1 |
| 6 | | 1 | 0-1 |
| 7 | | 1 | 0-1 |
+----+----------+-----+------+
7 rows in set
mysql> insert into tb_kind values(null," ",5,"0-1-5");
Query OK, 1 row affected
mysql> insert into tb_kind values(null," ",5,"0-1-5");
Query OK, 1 row affected
mysql> select * from tb_kind;
+----+----------+-----+-------+
| id | pname | pid | path |
+----+----------+-----+-------+
| 1 | | 0 | 0 |
| 2 | | 0 | 0 |
| 3 | | 0 | 0 |
| 4 | | 0 | 0 |
| 5 | | 1 | 0-1 |
| 6 | | 1 | 0-1 |
| 7 | | 1 | 0-1 |
| 8 | | 5 | 0-1-5 |
| 9 | | 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 | | 0 | 0 |
| 2 | | 0 | 0 |
| 3 | | 0 | 0 |
| 4 | | 0 | 0 |
| 5 | | 1 | 0-1 |
| 6 | | 1 | 0-1 |
| 7 | | 1 | 0-1 |
| 8 | | 5 | 0-1-5 |
| 9 | | 5 | 0-1-5 |
| 10 | NBA | 8 | 0-1-5-8 |
| 11 | CBA | 8 | 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 |
+---------------------+
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 |
+---------------------+
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 |
+------------+
11 rows in set
mysql> select concat(path,"-",id) as,id,name,path abs from tb_kind order by abs;
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 | | 0 |
| 0-1-5 | 5 | | 0-1 |
| 0-1-5-8 | 8 | | 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 | | 0-1-5 |
| 0-1-6 | 6 | | 0-1 |
| 0-1-7 | 7 | | 0-1 |
| 0-2 | 2 | | 0 |
| 0-3 | 3 | | 0 |
| 0-4 | 4 | | 0 |
+------------+----+----------+---------+
11 rows in set
mysql>
上のコードの中にスペースがある入力効果はとてもいいです。現地でテストしてください。エディタの問題でレイアウトが混乱しました。