Daney11 Posted February 10, 2007 Share Posted February 10, 2007 Hey Guys, Having trouble with my who's online script. Basically i want to echo out users who have been online within the last 5 minutes from my database, but no echo out people who havent been online in the last 5 minutes... My code is.. <?php $inactive = time()-(60*60*5); $strQuery = "SELECT * FROM managers WHERE manager_time > $inactive ORDER BY manager_time DESC"; $result = mysql_query($strQuery,$db) or die(mysql_error()); while ($myrow = mysql_fetch_array($result)) { ?> <td width="100"><?php echo stripslashes(date('H:i:s', $myrow['manager_time'])); ?></td> <?php } ?> However, this gets all managers out of the database reguardless of what time they have been online... Any ideas guys.. Thanks Dane Link to comment https://forums.phpfreaks.com/topic/37847-solved-dont-extract-timestamp-5-minutes/ Share on other sites More sharing options...
Jessica Posted February 10, 2007 Share Posted February 10, 2007 $fiveMinAgo = time()-(60*60*5); $strQuery = "SELECT * FROM managers WHERE manager_time > $fiveMinAgo ORDER BY manager_time DESC"; $inactive isn't defined, so you're getting where the time > 0. Link to comment https://forums.phpfreaks.com/topic/37847-solved-dont-extract-timestamp-5-minutes/#findComment-181162 Share on other sites More sharing options...
Daney11 Posted February 10, 2007 Author Share Posted February 10, 2007 Sorry i didnt post my $inactive.. Ive updated the script. Its still the same its gets out all times. But i cannot see why.... :S Link to comment https://forums.phpfreaks.com/topic/37847-solved-dont-extract-timestamp-5-minutes/#findComment-181163 Share on other sites More sharing options...
Jessica Posted February 10, 2007 Share Posted February 10, 2007 Is the field an integer/timestamp, or a MySQL DATETIME? Link to comment https://forums.phpfreaks.com/topic/37847-solved-dont-extract-timestamp-5-minutes/#findComment-181169 Share on other sites More sharing options...
Daney11 Posted February 10, 2007 Author Share Posted February 10, 2007 Its actually varchar(10) with $time = time(); inserted such as "1171067003" Link to comment https://forums.phpfreaks.com/topic/37847-solved-dont-extract-timestamp-5-minutes/#findComment-181172 Share on other sites More sharing options...
Jessica Posted February 10, 2007 Share Posted February 10, 2007 Change it to an INT and see if it works better? What is the value of $myrow['manager_time'] for the ones you're not expecting to get? Also, what is the value of $inactive? print the sql statement to make sure it's right. Link to comment https://forums.phpfreaks.com/topic/37847-solved-dont-extract-timestamp-5-minutes/#findComment-181174 Share on other sites More sharing options...
Daney11 Posted February 10, 2007 Author Share Posted February 10, 2007 Changed to INT but didnt work. Get the same thing.... The value of manager_time in the database, using INT, is ... 1171070900 the value of $inactive = $inactive = time()-(60*60*5); Link to comment https://forums.phpfreaks.com/topic/37847-solved-dont-extract-timestamp-5-minutes/#findComment-181175 Share on other sites More sharing options...
Daney11 Posted February 10, 2007 Author Share Posted February 10, 2007 I know what wrong i think..... According to echoing out $inactive = time()-(60*60*5); as stripslashes(date('H:i:s', $inactive); Thats telling me that the time - 60*60*5 is 5 hours behind..... Link to comment https://forums.phpfreaks.com/topic/37847-solved-dont-extract-timestamp-5-minutes/#findComment-181185 Share on other sites More sharing options...
Jessica Posted February 10, 2007 Share Posted February 10, 2007 It should be 60*5, 5 minutes is 300 seconds. My bad. The timezone doesn't matter, as it's always the same timezone. Link to comment https://forums.phpfreaks.com/topic/37847-solved-dont-extract-timestamp-5-minutes/#findComment-181192 Share on other sites More sharing options...
Daney11 Posted February 10, 2007 Author Share Posted February 10, 2007 yess. fixed. thanks mate. after echoing out $inactive i realised that the time is wrong.... thanks again. i can sleep now lol. Link to comment https://forums.phpfreaks.com/topic/37847-solved-dont-extract-timestamp-5-minutes/#findComment-181194 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.