我正在嘗試計算訪問者日期,以瞭解每月有多少次訪問&將結果發佈到jQuery圖表中。使用php/mysql按月訪問訪問者
好,所以下面的代碼「有效」,但它以某種方式計算一切* 2.如果有一個訪問者這個月它會輸出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數據庫。 –