【发布时间】:2016-02-26 22:56:28
【问题描述】:
我有一个图表,我想在其中填写有关我每个月有多少记录的信息。图表需要接收这种格式的数据:
data: [
["Jan", 140],
["Feb", 240],
["Mar", 190],
["Apr", 140],
["May", 180],
["Jun", 320],
["Jul", 270],
["Aug", 180]
],
我需要生成每个月有多少记录。我的数据库看起来像:
id | start | end |
------------------------------
1 | 2015-10-01 | 2015-10-31 |
2 | 2015-10-05 | 2015-10-09 |
3 | 2015-10-06 | 2015-10-07 |
4 | 2015-11-01 | 2015-11-02 |
5 | 2015-11-03 | 2015-11-06 |
6 | 2015-11-09 | 2015-10-13 |
7 | 2015-11-16 | 2015-10-18 |
8 | 2015-11-21 | 2015-10-29 |
所以我们在 10 月有 3 条记录,在 11 月有 5 条记录。 我应该如何正确初始化一个函数,最终将返回我可以传递给数据的正确外观格式? 我可以获取像
这样的记录型号:
function specialtest($start, $end) {
$q = ("SELECT count(*) as count FROM reservations WHERE end > '$start' and start < '$end'");
$query = $this->db->query($q);
print json_encode($query->result_array());
exit;
}
然后在Controller中:
$data = $this->model->specialtest($arg, $arg2);
但这并不是我所需要的。我每个月都需要这些记录而不调用任何函数参数,因为我不知道它们?有什么想法吗?
【问题讨论】:
-
用sql语句或者view取数据,用php展示
-
@Ilan Hasanov : 你想要一个 sql 查询来检索你想要的数据吗?
-
在将
count附加为列后,您是否尝试使用group by month。 -
i need those records each month without calling any function arguments as i don't know them- 好一个:D
标签: php mysql json codeigniter