我的网站上有一个模块,显示过去 30 天的收入。我的问题是我希望所有收入都按天分类,而不是按 24 小时分类。
这是我的代码:
$days = array(29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0);
foreach($days as $day)
{
$daybefore = $day -1;
if($day == 0)
{
$query = "SELECT SUM(earnings)
FROM earnings
WHERE `timestamp` <= CURRENT_DATE + INTERVAL
AND `timestamp` > CURRENT_DATE + INTERVAL -1 DAY";
}
if($day == 1)
{
$query = "SELECT SUM(earnings)
FROM earnings
WHERE `timestamp` <= CURRENT_DATE + INTERVAL -" . $day . "
AND `timestamp` > CURRENT_DATE + INTERVAL -" . $daybefore . " DAY";
}
问题是它会在查询后的 24 小时内获取所有数据。我想要的数据是:
今天 = 当天开始的所有数据。今天 = 从当天开始到当天结束的所有数据。等等。
感谢您的任何建议。