数据输出有关问题

WBOY
Release: 2016-06-13 11:50:04
Original
1340 people have browsed it

数据输出问题

本帖最后由 jy02409187 于 2014-01-10 11:53:14 编辑 现在有三张表,一级分类,二级分类,三级分类 

一级分类 catalog

 id  name  rank
 1    a1    99
 2    a2    98


二级分类 subCatalog

 id  name catalogId catalogName rank
 1    b1       1          a1     99
 2    b2       1          a1     98
 3    b3       2          a2     97
 4    b4       2          a2     96


三级分类 threeCatalog

 id  name catalogId catalogName subCatalog subCatalogName rank
 1    c1       1           a1         1           b1       99
 2    c2       1           a1         1           b1       98
 3    c3       1           a1         2           b2       97
 4    c4       2           a2         3           b3       96
 5    c5       2           a2         4           b4       95


请问用PHP怎么输出一个如下的JSON数组啊

{"catalog":[{
        "id" : 1,
        "name" : "a1",
        "subCatalog" : [{
            "id" : 1,
            "name" : "b1",
            "threeCatalog" : [{
                "id" : 1,
                "name" : "c1"
            }, {
                "id" : 2,
                "name" : "c2"
            }]
        }, {
            "id" : 2,
            "name" : "b2",
            "threeCatalog" : [{
                "id" : 3,
                "name" : "c3"
            }]
        }]
    }, {
        "id" : 2,
        "name" : "a2",
        "subCatalog" : [{
            "id" : 3,
            "name" : "b3",
            "threeCatalog" : [{
                "id" : 4,
                "name" : "c4"
            }]
        }, {
            "id" : 4,
            "name" : "b4",
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!