1
开始我需要循环通过一年的2012年12月间的月至2017年十一月开始那么一个月就是12,结束月份是11,起始年是2012年,收官之年的2017年PHP循环遍历月,在十二月
然后我询问与日期格式的数据库为2014年3月27日00:00:00
我知道我大约4年前做过这样的事情,但似乎无法能够螺母现在出来了。 这是我有:
$year_start = 2012;
$year_end = 2017;
$month_start = 12;
$month_end = 11;
$year = $year_start;
$month = $month_start;
$number_of_months = 3;
if ($month < 13 && $year < $year_end) {
$between_year_month = $year.'-'.$month;
//echo $between_year_month;
$query_total = "SELECT SUM(sales_points) FROM sales_list
WHERE user_id ='".$_SESSION['users_id']."'
AND sales_date BETWEEN '".$between_year_month."-01 00:00:00' AND '".$between_year_month."-30 23:59:59'";
echo $query_total;
$month++;
if($month == 13) {
$month = 1;
$year = $year + 1;
}
$between_year_month = $year.'-'.$month;
//echo $between_year_month;
}
您的帮助深表感谢。
我发布了n个答案,然后意识到我不知道你实际上有什么问题。 –
环路和做什么?无论如何,您可以将数据库中的日期截至一年。 – Jonast92