我有一个查询来获取按月份分组的插入次数。我已经安装并运行了beberlei Doctrine扩展,但数组返回的密钥是月份号。将如何在图表行中使用,我想显示月份名称而不是月份编号。
最好的方法是什么?
这是一个查询:
//get and format the current year
$date = new DateTime();
$year = $date->format('Y');
//create query
$qb = $this->_em->createQueryBuilder();
$qb->select(['MONTH(p.createdAt) as month', 'count(ccp) as insertions'])
->from(CareConnectPatient::class, 'ccp')
->join('ccp.person', 'p')
->where('YEAR(p.createdAt) = :year')->setParameter('year', $year);
$qb->groupBy('month');
return $qb->getQuery()->getScalarResult();
我这样做的结果是:
`$countMonths = count($cCPatientGroupedByMonth);
for ($count = 0; $count<$countMonths; $count++){
$arrayKeyAsMonth[$cCPatientGroupedByMonth[$count]['month']] = $cCPatientGroupedByMonth[$count]['insertions'];
}`
是什么给了我这样的东西:
array:3 [
4 => "1",
8 => "2",
9 => "2"
]
我知道什么是最好的方式使这看起来像:
array:3 [
april => "1",
august => "2",
september => "2"
]
抱歉英语不好,谢谢!
您尝试过使用MONTHNAME((函数吗?
而不是:
$qb->select(['MONTH(p.createdAt) as month', 'count(ccp) as insertions'])
尝试:
$qb->select(['MONTHNAME(p.createdAt) as month', 'count(ccp) as insertions'])