【发布时间】:2019-02-14 06:27:07
【问题描述】:
在phpmyadmin中执行时我有这个SQL语句结果很好:
SELECT COUNT(cid) as total from courier where pick_date > DATE_SUB(now(),
INTERVAL 6 MONTH) group by year(pick_date), MONTH(pick_date)
结果:
COUNT(cid)
221
380
368
315
140
204
54
但是当我在 PHP 中尝试时只获得一个计数
$out = array();
$sql="SELECT COUNT(cid) as total from courier where pick_date > DATE_SUB(now(), INTERVAL 6 MONTH) group by year(pick_date), MONTH(pick_date)";
$pquery=$pdo->query($sql);
$prow=$pquery->fetch_all(PDO::FETCH_ASSOC);
$out[]=$prow['total'];
echo implode( ", ", $out );
实际结果:221
Expected:
221
380
368
315
140
204
54
在此先感谢... :)
【问题讨论】:
-
这里 cid
s area different & you are getting its count only... Please post the result with cids 也...所以很容易找到解决方案 -
->fetch_all()是你的包装函数吗?因为标准是->fetchAll()。此外,由于->fetchAll()返回一个数组数组,因此您必须循环遍历结果