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>