【发布时间】:2015-08-16 12:45:15
【问题描述】:
我有这个数组:
array(3) {
[0]=>
object(stdClass)#232 (3) {
["id"]=>
string(2) "14"
["name"]=>
string(13) "pdfs Shoulder"
["type_id"]=>
string(1) "4"
}
[1]=>
object(stdClass)#231 (3) {
["id"]=>
string(2) "14"
["name"]=>
string(13) "pdfs Shoulder"
["type_id"]=>
string(1) "7"
}
[2]=>
object(stdClass)#230 (3) {
["id"]=>
string(2) "15"
["name"]=>
string(3) "112"
["type_id"]=>
string(1) "7"
}
}
使用foreach我会输出它,但是,有3个type_id键,一个是4,两个是7,所以输出是这样的:
Course Name: 4
File: pdfs Shoulder
Course Name: 7
File: pdfs Shoulder
Course Name: 7
File: 112
但我希望它是这样的:
Course Name: 4
File: pdfs Shoulder
Course Name: 7
File: pdfs Shoulder
File: 112
我不知道该怎么做...... 如果修改查询更容易解决,这是我使用的查询:
SELECT lm.id,lm.name,lm.local, lmr.access as access,lmr.type_id
FROM `media` as lm
LEFT JOIN `mediarel` as lmr
ON lm.id=lmr.media_id
WHERE `lmr`.`type_id` IN ({$ids})
AND lm.published = 1 and flag=1 and lmr.type='pmed' order by lmr.order
【问题讨论】:
-
你在用mysql吗?如果你是,你可以尝试使用
GROUP BYtype_id和GROUP_CONCAT -
也许我不知道如何使用/将它们放入查询中,但它没有给我需要的结果
-
但是是mysql吗?因为sql server不支持
GROUP_CONCAT -
是 mysql。我不确定如何使用它们 tbh