【发布时间】:2014-06-23 12:16:04
【问题描述】:
我需要按年(12 个月)按 json 格式打印 Total(count) 新闻存档,如下所示:
输出:
["January:31","February:28","March:0","April:130","May:450","June:0","July:0","August:0","September:0","October:520","November:20","December:31"]
PHP 代码:
SELECT COUNT(*) AS id,
YEAR(date) as `year`,
MONTH(date) as `month`,
MONTHNAME(date) as `month_name`,
FROM `aticle`
GROUP BY `year`, `month`;
注意: if we dont have news in any month print:0 即:"March:0","July:0".....
如何打印?!
【问题讨论】:
-
你能发布你目前所拥有的吗?
-
StackOverflow 将被用作指南来帮助您找到答案,我们将不会为您编写代码。到目前为止,您为解决这个问题写了什么?
-
SELECT COUNT(<column_containing_news_count>) AS num_of_articles, MONTHNAME(date) as month_name FROM aticle GROUP BY MONTHNAME(date);? -
@esqew:这是真的。但我对此一无所知。我的问题是这个!
-
@user27133 您可以先执行查询并将结果加载到数组中,不是吗?