July 24, 201016 yr Hi guys, Im setting the time using time(); in my mysql database, how can i workout 300 seconds from the current time on the database? if($data['last_active'] < time() -300) { } I figured it will be something simler to the above?
July 24, 201016 yr Author What format is $data['last_active'] in? Thats just demo text, its basicly getting the current set time() from the colum last_active in the table members. I want to work out, has 5 minutes past from the time that was set on user login in the database
July 24, 201016 yr I think it might be something like this: $time = -300; if($data['last_active'] == time_duration($time){ }
July 24, 201016 yr Thats just demo text, its basicly getting the current set time() from the colum last_active in the table members. I want to work out, has 5 minutes past from the time that was set on user login in the database Ok, so what format is the variable you're comparing in? Is it a Unix timestamp or a date format?
July 24, 201016 yr Author Ok, so what format is the variable you're comparing in? Is it a Unix timestamp or a date format? timestamp.. Im trying to get mysql to search for any accounts with isonline='1' then check with the time() function in php if the lastactive field has been more than 5 minutes since the last entry of the time();
July 24, 201016 yr Ok, try this: if (($lastActive + 300) < time()) { // timed out } Make sure you've set the timezone correctly before that code: date_default_timezone_set('Europe/London');
July 24, 201016 yr Personally. I'd rather let MySQL do the heavy lifting for you. Have a look at the TIMESTAMPDIFF() function. $qry = "SELECT TIMESTAMPDIFF(MINUTE, last_active, NOW()) as last_logged_in FROM `table`"; This will return a number which you can then easily compare with php. Obviously, you can also use clauses such as WHERE etc
July 24, 201016 yr Hey all, just so you all know this has been sorted, thankyou for the help you gave him. > Friend...
July 25, 201016 yr Author $this->last_active = $connect->mfq('SELECT * FROM mi5_members WHERE isonline="1"'); if($this->last_active['lastactive'] < time()-(30)) { $connect->mq('UPDATE mi5_members SET isonline="0" WHERE isonline="1"'); } The code above is not doing its job, What i need it to do is set any user that has isonline='1' to isonline="0" where the lastactive time has been more than 5 minutes.
July 25, 201016 yr $this->last_active = $connect->mfq('SELECT * FROM mi5_members WHERE isonline="1"'); if($this->last_active['lastactive'] < time()-(30)) { $connect->mq('UPDATE mi5_members SET isonline="0" WHERE isonline="1"'); } The code above is not doing its job, What i need it to do is set any user that has isonline='1' to isonline="0" where the lastactive time has been more than 5 minutes. Try this $this->last_active = $connect->mfq('SELECT * FROM mi5_members WHERE isonline="1"'); if($this->last_active['lastactive'] > time()-(300)) { $connect->mq('UPDATE mi5_members SET isonline="0" WHERE isonline="1"'); }
July 25, 201016 yr Author Try this $this->last_active = $connect->mfq('SELECT * FROM mi5_members WHERE isonline="1"'); if($this->last_active['lastactive'] > time()-(300)) { $connect->mq('UPDATE mi5_members SET isonline="0" WHERE isonline="1"'); } Beat you to it! Heres what i did: $last_active = mysql_fetch_array(mysql_query('SELECT * FROM mi5_members WHERE isonline="1" AND lastactive < "'.time(-10).'"')); if($last_active['lastactive'] < time()-300) { mysql_query('UPDATE mi5_members SET isonline="0" WHERE lastactive < "'.time(-300).'"'); } And it works perfect ;D
July 25, 201016 yr Beat you to it! Heres what i did: $last_active = mysql_fetch_array(mysql_query('SELECT * FROM mi5_members WHERE isonline="1" AND lastactive < "'.time(-10).'"')); if($last_active['lastactive'] < time()-300) { mysql_query('UPDATE mi5_members SET isonline="0" WHERE lastactive < "'.time(-300).'"'); } And it works perfect ;D Aw well lol just had my sign turned the wrong way but yea i was gonna tell u 300 means 5 mins
July 25, 201016 yr Author Aw well lol just had my sign turned the wrong way but yea i was gonna tell u 300 means 5 mins Aha, I know you told me that over msn when you coming back anyway? Ive got something to show you?
Create an account or sign in to comment