【发布时间】:2016-11-20 11:45:39
【问题描述】:
我正在尝试计算访问者日期,以查看每月有多少访问量并将结果发布到 jquery 图表中。
好的,下面的代码“有效”,但它以某种方式计算所有内容 * 2。如果本月有 1 个访问者,它将输出 2,这是为什么呢?
我也想知道如何使这段代码更小? $jan $feb 等似乎不应该这样做,但我是一个初学者,所以我真的不知道如何使这段代码变得更小和更好。有人可以帮我解决这个问题吗?
数据库:
date
2016-11-17 16:36:12
PHP:
$jan = ''; $feb = ''; $maa = ''; $apr = ''; $mei = ''; $jun = ''; $jul = ''; $aug = ''; $sep = ''; $okt = ''; $nov = ''; $dec = '';
foreach($dates as $date){
$month = date_parse_from_format("Y-m-d H:i:s", $date->date);
if($month ["month"] == '01'){$jan .= $month ["month"];}
if($month ["month"] == '02'){$feb .= $month ["month"];}
if($month ["month"] == '03'){$maa .= $month ["month"];}
if($month ["month"] == '04'){$apr .= $month ["month"];}
if($maand["month"] == '05'){$mei .= $month ["month"];}
if($maand["month"] == '06'){$jun .= $month ["month"];}
if($maand["month"] == '07'){$jul .= $month ["month"];}
if($maand["month"] == '08'){$aug .= $month ["month"];}
if($maand["month"] == '08'){$sep .= $month ["month"];}
if($maand["month "] == '10'){$okt .= $month ["month"];}
if($maand["month "] == '11'){$nov .= $month ["month"];}
if($maand["month "] == '12'){$dec .= $month ["month"];}
}
【问题讨论】:
-
您是否从数据库中获取此数据?
-
是的,来自mysql数据库。
标签: javascript php date filter