function convertDates($timestamp) {
return date('Y-m-d', $timestamp);
}
$days = array(); //storing databases php time();
$complete = array(); //storing the generated missing days
$occurrences = array(); //finding how many php time() are on same day
$zero = array(); //instead of storing occurrence as 1, store it as zero
$query = mysql_query("SELECT `login` FROM `statistics` ORDER BY `login` ASC");
while($rows = mysql_fetch_array($query)) {
$days[] = $rows['login']; //filling array with times
}
$days[] = time(); //append current time
for($i = 0; $i < count($days); $i++) {
$complete[] = convertDates($days[$i]);
$difference = isset($days[$i+1]) ? $days[$i+1] - $days[$i] : 0;
if($difference >= 86400) {
$difference = ceil(abs($difference/86400));
$fill = $days[$i];
for($k = 0; $k < $difference; $k++) {
$fill += 86400;
$complete[] = convertDates($fill);
$zero[] = convertDates($fill);
}
}
}
$occurrences = array_count_values($complete);
$complete = array_unique($complete);
$zero = array_unique($zero);
sort($complete);
echo "[";
for($i = 0; $i < count($zero); $i++) {
echo "[\"".$zero[$i]."\",0], ";
}
for($i = 0; $i < count($occurrences); $i++) {
if($i == count($occurrences)-1)
echo "[\"".$complete[$i]."\",".$occurrences[$complete[$i]]."]";
else {
echo "[\"".$complete[$i]."\",".$occurrences[$complete[$i]]."], ";
}
}
echo "]";
我正在将点绘制到 jqplot 图中,对于我需要定义用户未登录天数的统计数据。让我们称这些“差距”
用户于 2012 年 3 月 25 日登录,5 天后未重新登录。现在是 2012 年 3 月 30 日。我必须从这两个日期中生成那些缺失的日子。
我目前的算法似乎不起作用。我不知道出了什么问题。
数据库中的日期来自 phptime();
我将所有值存储到一个数组中$days
这是脚本生成的登录表的输出。请注意,它是为 jqplot 编码的:
[["2012-04-01",0], ["2012-04-02",0], ["2012-04-03",0], ["2012-04-04",0], ["2012-04-05",0], ["2012-04-07",0], ["2012-04-08",0], ["2012-04-09",0], ["2012-04-10",0], ["2012-04-11",0], ["2012-04-12",0], ["2012-04-13",0], ["2012-04-14",0], ["2012-04-15",0], ["2012-04-16",0], ["2012-04-17",0], ["2012-04-18",0], ["2012-04-19",0], ["2012-04-20",0], ["2012-04-21",0], ["2012-04-22",0], ["2012-04-23",0], ["2012-04-24",0], ["2012-04-25",0], ["2012-04-26",0], ["2012-04-27",0], ["2012-04-28",0], ["2012-04-29",0], ["2012-04-30",0], ["2012-03-31",1], ["2012-04-01",2], ["2012-04-02",2], ["2012-04-03",1], ["2012-04-04",19], ["2012-04-05",13], ["2012-04-06",8], ["2012-04-07",1], ["2012-04-08",1], ["2012-04-09",4], ["2012-04-10",1], ["2012-04-11",1], ["2012-04-12",2], ["2012-04-13",1], ["2012-04-14",1], ["2012-04-15",1], ["2012-04-16",2], ["2012-04-17",10], ["2012-04-18",1], ["2012-04-19",1], ["2012-04-20",1], ["2012-04-21",1], ["2012-04-22",1], ["2012-04-23",1], ["2012-04-24",1], ["2012-04-25",1], ["2012-04-26",1], ["2012-04-27",1], ["2012-04-28",1], ["2012-04-29",1], ["2012-04-30",2]]
我的脚本不工作。如何正确生成用户未登录的日期?
感谢您的时间。