私はこのクエリを持っています:
SELECT
tud.detail_company_name AS company_name,
tud.detail_country AS company_country,
trv.review_title AS review_title
FROM users_detail tud
INNER JOIN users_auth tua
ON tud.user_id = tua.user_id
LEFT JOIN reviews trv
ON tud.user_id = trv.review_company_id
WHERE
tua.auth_user_type = "company" OR tua.auth_user_type = "guestcompany"
クエリは正常に機能し、次のような結果が返されます。
Array
(
[0] => Array
(
[company_name] => The Coffee Brewery
[company_country] => US
[review_title] =>
)
[1] => Array
(
[company_name] => Crea Nail Art Studio
[company_country] => SG
[review_title] =>
)
[2] => Array
(
[company_name] => Hello Mall
[company_country] => JP
[review_title] => Fake goods!
)
[3] => Array
(
[company_name] => Hello Mall
[company_country] => JP
[review_title] => Never buy in there!
)
)
お気づきのように、配列キー 2 と 3 のcompany_nameは同じですが、 review_titleは異なります。1 つの結果に結合し、コンマで区切る必要がある可能性はありますか? たとえば、次の結果を言います。
Array
(
[0] => Array
(
[company_name] => The Coffee Brewery
[company_country] => US
[review_title] =>
)
[1] => Array
(
[company_name] => Crea Nail Art Studio
[company_country] => SG
[review_title] =>
)
[2] => Array
(
[company_name] => Hello Mall
[company_country] => JP
[review_title] => Fake goods!, Never buy in there!
)
)
編集
応答が次の場合はどうなりますか。
Array
(
[0] => Array
(
[company_name] => The Coffee Brewery
[company_country] => US
[review_title] =>
[review_approved] =>
)
[1] => Array
(
[company_name] => Crea Nail Art Studio
[company_country] => SG
[review_title] =>
[review_approved] =>
)
[2] => Array
(
[company_name] => Hello Mall
[company_country] => JP
[review_title] => Fake goods!
[review_approved] => 1
)
[3] => Array
(
[company_name] => Hello Mall
[company_country] => JP
[review_title] => Never buy in there!
[review_approved] => 0
)
)
review_titleに0のreview_approved を含めないようにするにはどうすればよいGROUP_CONCAT
ですか? それで、このように出力されますか?
Array
(
[0] => Array
(
[company_name] => The Coffee Brewery
[company_country] => US
[review_title] =>
)
[1] => Array
(
[company_name] => Crea Nail Art Studio
[company_country] => SG
[review_title] =>
)
[2] => Array
(
[company_name] => Hello Mall
[company_country] => JP
[review_title] => Fake goods!
)
)