我对PHP和MySQL相当陌生,所以我需要一些帮助。需要帮助检查用户是否在线
<?php
function Agotime($date)
{
if(empty($date)) {
return "No date provided";
}
$periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
$lengths = array("60","60","24","7","4.35","12","10");
$now = time();
$unix_date = strtotime($date);
// check validity of date
if(empty($unix_date)) {
return "Unknown";
}
// is it future date or past date
if($now > $unix_date) {
$difference = $now - $unix_date;
$tense = "ago";
} else {
$difference = $unix_date - $now;
$tense = "from now";
}
for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
$difference /= $lengths[$j];
}
$difference = round($difference);
if($difference != 1) {
$periods[$j].= "s";
}
return "$difference $periods[$j] {$tense}";
}
$date = $run_user['lastloggedin'];
$result = Agotime($date); // 2 days ago
$serverjoins = $run_user['server_joins'];
?>
我有一个代码,它的工作,因为它应该的,但有一个问题,我有另一行我的数据库在线调用,如果设置为true,我希望它显示在线而不是例如Last Seen:1小时前 任何人都可以告诉我在哪里放什么?
目前尚不清楚。哪里数据库结果?你如何将它与这个功能结合起来? – Javad
@Javad我不明白你的回复,你能否更清楚一点? – ImSchnebz
我的意思是来自数据库的'$ date'?您提供的此功能仅用于比较日期和时间 – Javad