cakephp一年中每月的COUNT个项目 [英] cakephp COUNT items per month in a year
本文介绍了cakephp一年中每月的COUNT个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你如何使用cakephp来计算,例如一年中每个月发布的帖子数?
How do you use cakephp to count, for example the number of posts, made every month in a year?
最好使用Model-> find('count')并获取数组中的数据。
Preferably using Model->find('count') and get the data in an array.
推荐答案
这很接近
查询
$ data = $ this-> (SELECT COUNT(id),MONTH(created)FROM posts GROUP BY YEAR(created),MONTH(created););
Query $data = $this->Post->query("SELECT COUNT(id),MONTH(created) FROM posts GROUP BY YEAR(created), MONTH(created);");
strong>
Return
Array
(
[0] => Array
(
[0] => Array
(
[COUNT(id)] => 1
[MONTH(created)] => 3
)
)
[1] => Array
(
[0] => Array
(
[COUNT(id)] => 2
[MONTH(created)] => 4
)
)
)
这篇关于cakephp一年中每月的COUNT个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文