Alright so when the user logs in, a session is started and Status
in the database is updated to '1'.
When the user logs out, the session is ended and Status
in the database is updated to '0'.
The issue is, the session ends when a user closes his web browser, which is perfectly okay, but the database Status
is not updated which shows the user still online.
Suggestions?
EDIT : This is the new "online-staff" section.
<?php
include 'connection.php';
$query = "SELECT * FROM Admins WHERE AdminLevel>='1' AND Status='1'";
$result = mysqli_query($connect,$query);
echo "
<table class='table-fill'>
<thead>
<tr>
<th class='text-left' style='padding-left: 12px; padding-right: 12px;';></th>
</tr>
</thead>
<tbody class='table-hover'>";
if (($result->num_rows) >= 1) {
$results = mysqli_fetch_array($result);
$currentTime = NOW();
while ($results) {
$visitTime = $results['LastVisited'];
$interval = ($visitTime->diff($currentTime))->minutes;
if ($interval<=15) {
if ($results['AdminLevel'] == 3){
$rank = 'In-Training/Intern';
}elseif ($results['AdminLevel'] == 6){
$rank = 'Community Moderator';
}elseif ($results['AdminLevel'] == 9){
$rank = 'Senior Moderator';
}elseif ($results['AdminLevel'] == 12){
$rank = 'Supervisor';
}elseif ($results['AdminLevel'] == 15){
$rank = 'Administrator';
}elseif ($results['AdminLevel'] == 18){
$rank = 'Senior Administrator';
}elseif ($results['AdminLevel'] == 21){
$rank = 'Staff Advisor';
}elseif ($results['AdminLevel'] == 24){
$rank = 'Engineer';
}elseif ($results['AdminLevel'] == 27){
$rank = 'Vice Chairman';
}elseif ($results['AdminLevel'] == 30){
$rank = 'Chairman';
}elseif ($results['AdminLevel'] == 33){
$rank = 'Website Engineer';}
echo "<tr>";
echo "<td>" . $results['Username'] . " - " . $rank . "</td>";}
}
}else{
echo "<tr>";
echo "<td>" . 'There are no staff members online.' . "</td>";
}
echo " </tbody>
</table>";
?>