下面一段代码是创建相应数据库的sql代码:
复制代码 代码如下:
//////////////
//////无限分类的数据库设计及样例
//////////////
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>
下面是php源文件:
复制代码 代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<!--显示结果
新闻
体育新闻
篮球新闻
NBA
CBA
足球新闻
娱乐新闻
财经新闻
视频
图片
博客
-->
<?
$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>
</html>
上面的代码中其实中间有空格的输入效果还是非常不错的,请大家本地测试。因编辑器问题导致排版混乱。
复制代码 代码如下:
//////////////
//////无限分类的数据库设计及样例
//////////////
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>
下面是php源文件:
复制代码 代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<!--显示结果
新闻
体育新闻
篮球新闻
NBA
CBA
足球新闻
娱乐新闻
财经新闻
视频
图片
博客
-->
<?
$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>
</html>
上面的代码中其实中间有空格的输入效果还是非常不错的,请大家本地测试。因编辑器问题导致排版混乱。
标签:
PHP无限分类
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“比较简单实用的PHP无限分类源码分享(思路不错)”评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?