我正在尝试获取我在桌子上的所有详细信息,但将它们按两个不同的列名一个接一个地分组,并从 php 中获取相同的
例子:
id name url category subcategory
/*------------------------------------------------------/*
1 google g.gl partner associative
2 fb f.b sponsor main
3 yahoo y.ho partner color
4 stack st.ck sponsor main
5 mys l.my sponsor sub
6 bang b.lo sponsor parent
7 xyz x.yz partner color
我终于想要什么
id name url category subcategory
/*------------------------------------------------------/*
1 google g.gl partner associative
3 yahoo y.ho partner color
7 xyz x.yz partner color
2 fb f.b sponsor main
4 stack st.ck sponsor main
6 bang b.lo sponsor parent
5 mys l.my sponsor sub
首先category按id分组排序,subcategory再按subcategory升序分组排序。
另外,我如何使用 php 获取相同的内容
我的尝试:
mysql:
SELECT category, GROUP_CONCAT(subcategory) , GROUP_CONCAT(name) , GROUP_CONCAT(url)
FROM list
GROUP BY category
PHP:
1. mysql_fetch_array to fetch everything..
2. explode subcategory and every other concated values and then echo them