Morgan Green Morgan Green - 2 years ago 88
SQL Question

Get Time From 5 Minutes Prior

I'm working on User Functions for the CMS I'm working on and I have users updated on each page load Using

if(User("online") == true) {

(Yes User Online Works, That's my function to check online users)
And now my times are updated correctly hooking into the LastOnlineUpdate function then running my class function

public function SessionUpdate($arg) {
$query = <<<SQL
UPDATE {$this->tprefix}online
SET remote = :remote, timestamp = :timestamp
WHERE userid = :arg
$resource = $this->db->db->prepare( $query );
$resource->execute( array(
':remote' => $_SERVER['REMOTE_ADDR'],
':timestamp' => time(),
':arg' => $arg,

Now whenever I go through my pages it updates the user by having the first code within my preloaded file, now I've hit my roadblock though with something I've never done and that's to take the time that's been inserted into my table, select it if the time is less than five minutes and utilize it for my online users section

public function OnlineUsers() {
$query = <<<SQL
SELECT userid
FROM {$this->tprefix}online
WHERE timestamp > time(5Minutes)
$resource = $this->db->db->prepare( $query );
$this->onlinecount = $resource->rowCount();
if($resource->rowCount() == 0 ) {
$this->onlineusers = "No User's Online";
foreach($resource as $row) {
self::ConvertIDToName("displayname"); //Can be display, user, first or whatever else for the argument, The onlineusers variable is then set based off that query

Answer Source
$minutes = 5;
$date = gmdate('Y-m-d H:i:s'); //
$date_plus_minutes = gmdate('Y-m-d H:i:s', ( time() + $minutes * 60 ) );
$date_minus_minutes = gmdate('Y-m-d H:i:s', ( time() - $minutes * 60 ) );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download