[英]PHP MySQL Group By result in array
**********************
* id * typ * cl *
**********************
* 1 * 1 * 1 *
* 2 * 4 * 1 *
* 3 * 7 * 1 *
* 4 * 2 * 2 *
* 5 * 4 * 2 *
* 6 * 8 * 2 *
**********************
hi frnz, I have a problem with mysql group by... tired of looking on the google so finally posting it here... my table structure is as showing above. 嗨frnz,我有一个问题与mysql组...厌倦了在谷歌上看,所以最后在这里发布...我的表结构如上所示。 I am using the following query... 我使用以下查询...
$sql2w=executeQuery("select * from logo group by cl ");
while($line2=mysql_fetch_array($sql2)){
echo $line2['typ'];
}
I am getting 1 and 2 in the result, but I want the result in this format.. 1,4,7 and 2,4,8 in string or in array format... 我在结果中得到1和2,但我想要这种格式的结果.. 1,4,7和2,4,8字符串或数组格式...
I hope I am clear what I want... 我希望我清楚我想要的......
I am only getting the first row values of "typ" column but I want all rows values in array after grouping the "cl" column.. 我只得到“typ”列的第一行值,但我希望在对“cl”列进行分组后,数组中的所有行值。
Thanks in advance 提前致谢
Use GROUP_CONCAT()
: 使用GROUP_CONCAT()
:
SELECT cl, GROUP_CONCAT(typ) FROM logo GROUP BY cl
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.