目前,我尝试从我的网站上注册获取统计数据。 要获取统计数据,我使用此功能:
public function get_stats_10_days_signup()
{
try
{
$data_stat = Array();
$stmt = $this->db->prepare("SELECT DAY(added) as DisplayDay , COALESCE(COUNT( added ), 0) as DisplayUsers FROM users WHERE added > DATE_SUB(NOW(), INTERVAL 7 DAY) GROUP BY DAY( added )");
$stmt->execute();
$message = '';
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
// do loop stuff
$message .= '[';
$message .= $row['DisplayDay'];
$message .= ', '.$row['DisplayUsers'];
$message .= '],';
}
return $message;
}
catch(PDOException $e)
{
return $e;
}
}
但结果是:
Day Signup
2017-03-17 2
2017-03-20 4
2017-03-23 1
当我没有记录时,我想要的是0,因为我想在图表上使用这些数据:
Day Signup
2017-03-17 2
2017-03-18 0
2017-03-19 0
2017-03-20 4
2017-03-21 0
2017-03-22 0
2017-03-23 1