Home > Backend Development > PHP Tutorial > 非递归无限分类的,有关问题,请下

非递归无限分类的,有关问题,请下

WBOY
Release: 2016-06-13 11:30:38
Original
835 people have browsed it

非递归无限分类的,问题,请高手指点下

本帖最后由 vbker 于 2012-09-05 10:19:59 编辑 数据库字段如下,暂时以地区代表栏目,cid为栏目ID,category为栏目名,chain为关系树,rank为栏目排序
<br />mysql> select * from mc_category;<br />+-----+----------+--------------+------+<br />| cid | category | chain        | rank |<br />+-----+----------+--------------+------+<br />|   1 | 国内     | 0_1          |    2 |<br />|   2 | 国外     | 0_2          |    1 |<br />|   3 | 华北     | 0_1_3        |    2 |<br />|   4 | 东北     | 0_1_4        |    1 |<br />|   5 | 西部     | 0_1_5        |    3 |<br />|   6 | 河南     | 0_1_3_6      |    1 |<br />|   7 | 郑州     | 0_1_3_6_7    |    2 |<br />|   8 | 巩义     | 0_1_3_6_7_8  |    1 |<br />|   9 | 洛阳     | 0_1_3_6_9    |    1 |<br />|  10 | 偃师     | 0_1_3_6_9_10 |    1 |<br />|  11 | 辽宁     | 0_1_4        |    3 |<br />|  12 | 吉林     | 0_1_4_11_12  |    1 |<br />|  13 | 上街     | 0_1_3_6_7_13 |    2 |<br />+-----+----------+--------------+------+<br />
Copy after login


使用
select category,chain from mc_category group by chain order by chain;
Copy after login

可以按照正确的父子关系列出目录树,但是我现在还需要让同级的栏目按照rank值进行排序,这个用mysql可以做到么?




======================================================================
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template