I have a mysql table called users with the columns username and status. The status is a timestamp that automatically updates whenever a user opens a new page on my website.
name:status type:timestamp(6)
attributes:on update CURRENT_TIMESTAMP
null:No default:CURRENT_TIMESTAMP(6)
extra:ON UPDATE CURRENT_TIMESTAMP
On their profile page, i'd like for it to show if theyre online or offline. I've tried the following code but it always shows "Name" is online, regardless of whether their last action was more than one minute ago.
<?php
$test = "SELECT status FROM users where username = '".$user."'"
or die(mysql_error());
$result = $link->query($test);
$row = $result->fetch_array(MYSQLI_NUM);
$mysql_timestamp = $row[0];
if(strtotime($mysql_timestamp) > strtotime("-1 minute")) {
echo "".$user." is online";
} ?>
Im new to php and just getting the hang of it. Any help would be appreciated. Thanks.