gpt4 book ai didi

php mysql 分组依据

转载 作者:行者123 更新时间:2023-11-29 04:18:30 26 4
gpt4 key购买 nike

这是我的 table

 row  | car_id | car_model | car_features |
1 1 CAR 1 Features 1
2 2 CAR 2 Features 2
3 2 CAR 2 Features 3

我想把它变成这样

 row  | car_id | car_model | car_features |
1 1 CAR 1 Features 1
2 2 CAR 2 Features 2, Features 3

这是我的 php mysql 脚本:

<?php
$con = mysql_connect("localhost", "root", "root");
mysql_select_db("car", $con);
$format = mysql_query("SELECT c.* , p.*, d.*,f.* ,e.* FROM bsi_car_master c,bsi_car_type p, bsi_car_vendor d, bsi_selected_features f, bsi_car_features e WHERE c.car_type_id=p.id AND c.car_vendor_id=d.id AND c.car_id = f.car_id AND f.features_id = e.id");
$row = 1;

while($srow = mysql_fetch_array($format))
{
blah blah blah....
}
?>

最佳答案

GROUP_CONCATGROUP BY 一起使用。试试这个-

SELECT `row`, `car_id`, `car_model`, GROUP_CONCAT(`car_features`, ',') 
FROM your_table GROUP BY `car_id`

关于php mysql 分组依据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33208411/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com