【发布时间】:2016-08-08 10:32:15
【问题描述】:
这是我的表,我需要从我的 MySQL 数据库中获取所有数据,这些数据将显示 30 天,计算每天的订单总数。而且还会有一个日期范围。
示例 1:当前日期是 2016 年 8 月 8 日。我需要显示从 2016 年 8 月 8 日开始的最近 30 天。
Order table
id | customer_id | num_of_order |date
---+-------------+--------------+--------
1 | 10001 | 1 | 2016-08-08 07:23:50
2 | 10002 | 4 | 2016-08-07 11:33:50
3 | 10003 | 2 | 2016-08-06 15:44:50 //same day
4 | 10001 | 5 | 2016-08-06 20:50:50 //same day
5 | 10004 | 3 | 2016-08-04 11:17:50
现在它会显示预期的输出:
array (
[0] => array (
[date] => 2016-08-08
[total_orders] => 1
)
[1] => array (
[date] => 2016-08-07
[total_orders] => 4
)
[2] => array (
[date] => 2016-08-06
[total_orders] => 7
)
[3] => array (
[date] => 2016-08-05
[total_orders] => 0 //no orders but still need to include in the output
)
[4] => array (
[date] => 2016-08-04
[total_orders] => 3
)
//and so forth (July 09, 2016).....
)
是否有任何用于此的 PHP codeigniter 代码?
【问题讨论】:
-
What have you tried so far? 请edit 您的问题显示您遇到问题的代码的minimal reproducible example,然后我们可以尝试帮助解决具体问题。您还应该阅读How to Ask。
标签: php mysql arrays database codeigniter