我有一个sql查询:
SELECT
DATE,
ID_DOMAIN,
SUM(CLICKS) AS CLICKS,
SUM(ADS) AS ADS,
SUM(CONVERSION) AS CONVERSION,
FROM website_stats
WHERE ID_USER_PRODUCT_DIFFUSER = :id_user_product_diffuser
AND DATE >= :date_begin
AND DATE <= :date_end
AND ID_DOMAIN != 0
GROUP BY DATE, ID_DOMAIN;
在我的 PDO fetchAll
,我用 $sth->fetchAll(PDO::FETCH_ASSOC | PDO::FETCH_GROUP)
. 然后我得到这个输出:
array(2) {
["2018-09-14"]=>
array(2) {
[0]=>
array(4) {
["ID_DOMAIN"]=>
string(1) "7"
["CLICKS"]=>
string(4) "1092"
["ADS"]=>
string(4) "1070"
["CONVERSION"]=>
string(3) "269"
}
[1]=>
array(4) {
["ID_DOMAIN"]=>
string(1) "9"
["CLICKS"]=>
string(3) "459"
["ADS"]=>
string(3) "452"
["CONVERSION"]=>
string(2) "56"
}
}
["2018-09-15"]=>
array(2) {
[0]=>
array(4) {
["ID_DOMAIN"]=>
string(1) "7"
["CLICKS"]=>
string(3) "914"
["ADS"]=>
string(3) "880"
["CONVERSION"]=>
string(3) "166"
}
[1]=>
array(4) {
["ID_DOMAIN"]=>
string(1) "9"
["CLICKS"]=>
string(3) "365"
["ADS"]=>
string(3) "361"
["CONVERSION"]=>
string(2) "57"
}
}
}
但是对于我的代码,我需要id\u域在我的子数组中有一个密钥。没有循环就可以吗?我是说,只是 PDO::FETCH*
? 实际上,我需要这样一个数组:
array(2) {
["2018-09-14"]=>
array(3) {
[7]=>
array(3) {
["CLICKS"]=>
string(4) "1092"
["ADS"]=>
string(4) "1070"
["CONVERSION"]=>
string(3) "269"
}
[9]=>
array(3) {
["ID_DOMAIN"]=>
string(1) "9"
["CLICKS"]=>
string(3) "459"
["ADS"]=>
string(3) "452"
["CONVERSION"]=>
string(2) "56"
}
}
["2018-09-15"]=>
array(2) {
[7]=>
array(3) {
["ID_DOMAIN"]=>
string(1) "7"
["CLICKS"]=>
string(3) "914"
["ADS"]=>
string(3) "880"
["CONVERSION"]=>
string(3) "166"
}
[9]=>
array(3) {
["CLICKS"]=>
string(3) "365"
["ADS"]=>
string(3) "361"
["CONVERSION"]=>
string(2) "57"
}
}
}
我搜索了很长一段时间好的pdo获取模式,但似乎没有人在这个网站上有这个问题:/
提前感谢:)
暂无答案!
目前还没有任何答案,快来回答吧!