我對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