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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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" Quote Link to comment 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. Quote Link to comment 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); Quote Link to comment 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..... Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.