【问题标题】:mysql query and php code for display ul li data用于显示ul li数据的mysql查询和php代码
【发布时间】:2015-03-02 21:29:04
【问题描述】:

我有两张桌子tbl_category

id category 
1   cat1 
2   cat2
3   cat3

第二张桌子Tbl_book

id  cat_id  book_name
1    1      book1
2    1      book2
3    2      book4
4    1      book5

用于显示的mysql查询和php代码

 cat1  book1  book2 book5 
 cat2  book4

【问题讨论】:

    标签: php mysql


    【解决方案1】:

    怎么样

    select c.category, 
           group_concat(b.bookname separator ' ') as books
    from tbl_category c
    inner join tbl_book b on b.cat_id = c.id
    group by c.category
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-27
    • 1970-01-01
    • 1970-01-01
    • 2015-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多