I'm trying to make a simple PHP function to format when the user was last active. I've been awake for a while and the answer just isn't coming to me.
The database connects just fine.
Any idea why my while loops are timing out?
function showActiveUsers(){
$host_name = '#####';
$database = '#####';
$user_name = '#####';
$password = '#####';
$conn = new mysqli($host_name, $user_name, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM user ORDER BY last_active DESC";
$result = $conn->query($sql);
$conn->close();
$ago = 0;
$d = 0;
$h = 0;
$m = 0;
foreach($result as $check)
{
$ago = time()-$check["last_active"];
if($ago<=120)
{
echo '<p>'.$check["username"].'<img width="10px" src="res/activedot.png"/></p>';
}
else
{
$d = 0;
$h = 0;
$m = 0;
while($ago<=86400)
{
$d++;
$ago = $ago-86400;
}
while($ago<=3600)
{
$h++;
$ago = $ago-3600;
}
while($ago<=60)
{
$m++;
$ago = $ago-60;
}
}
}
}
It's probably insanely simple and I've just been awake way too long.