seany123 Posted May 1, 2009 Share Posted May 1, 2009 here is the code... <?php function timeSince($urtime) { $seconds = (((time() - $urtime) / 1) % 60); $minutes = (intval((time() - $urtime) / 60) % 60); $hours = intval((time() - $urtime) / 3600); $days = intval((time() - $urtime) / 86400); $weeks = intval((time() - $urtime) / 604800); $months = intval((time() - $urtime) / 2419200); $years = intval((time() - $urtime) / 29030400); $result = array(); $result['years'] = ($years) ? sprintf('%u year%s,', number_format($years), ($years > 1) ? 's' : '') : FALSE; $result['months'] = ($months) ? sprintf('%u month%s,', number_format($months), ($months > 1) ? 's' : '') : FALSE; $result['weeks'] = ($weeks) ? sprintf('%u week%s,', number_format($weeks), ($weeks > 1) ? 's' : '') : FALSE; $result['days'] = ($days) ? sprintf('%u day%s,', number_format($days), ($days > 1) ? 's' : '') : FALSE; $result['hours'] = ($hours) ? sprintf('%u hour%s,', number_format($hours), ($hours > 1) ? 's' : '') : FALSE; $result['minutes'] = ($minutes) ? sprintf('%u minute%s', $minutes, ($minutes > 1) ? 's' : FALSE) : FALSE; $result['seconds'] = ($seconds) ? sprintf('%s %u second%s',($minutes) ? 'and' : '', $seconds, ($seconds > 1) ? 's' : FALSE) : FALSE; return (count($result) == 0) ? 'Never' : implode(' ', $result).' ago'; } ?> can anyone help me change this code, so if seconds is <= 1 then it will echo "NOW!" Link to comment https://forums.phpfreaks.com/topic/156437-solved-help-with-this-please/ Share on other sites More sharing options...
Gighalen Posted May 1, 2009 Share Posted May 1, 2009 if-else? lolz Link to comment https://forums.phpfreaks.com/topic/156437-solved-help-with-this-please/#findComment-823694 Share on other sites More sharing options...
Ken2k7 Posted May 1, 2009 Share Posted May 1, 2009 <?php function timeSince($urtime) { $seconds = (((time() - $urtime) / 1) % 60); $minutes = (intval((time() - $urtime) / 60) % 60); $hours = intval((time() - $urtime) / 3600); $days = intval((time() - $urtime) / 86400); $weeks = intval((time() - $urtime) / 604800); $months = intval((time() - $urtime) / 2419200); $years = intval((time() - $urtime) / 29030400); $result = array(); $result['years'] = ($years) ? sprintf('%u year%s,', number_format($years), ($years > 1) ? 's' : '') : FALSE; $result['months'] = ($months) ? sprintf('%u month%s,', number_format($months), ($months > 1) ? 's' : '') : FALSE; $result['weeks'] = ($weeks) ? sprintf('%u week%s,', number_format($weeks), ($weeks > 1) ? 's' : '') : FALSE; $result['days'] = ($days) ? sprintf('%u day%s,', number_format($days), ($days > 1) ? 's' : '') : FALSE; $result['hours'] = ($hours) ? sprintf('%u hour%s,', number_format($hours), ($hours > 1) ? 's' : '') : FALSE; $result['minutes'] = ($minutes) ? sprintf('%u minute%s', $minutes, ($minutes > 1) ? 's' : FALSE) : FALSE; $result['seconds'] = ($seconds) ? sprintf('%s %u second%s',($minutes) ? 'and' : '', $seconds, ($seconds > 1) ? 's' : FALSE) : FALSE; if ($seconds <= 1) return "NOW!"; else return (count($result) == 0) ? 'Never' : implode(' ', $result).' ago'; } ?> Like that? Link to comment https://forums.phpfreaks.com/topic/156437-solved-help-with-this-please/#findComment-823696 Share on other sites More sharing options...
seany123 Posted May 1, 2009 Author Share Posted May 1, 2009 yes thank you ken that worked but I have just come across a different error now. its displaying things like "1 day, 31 hours, 56 minutes and 33 seconds ago" why is it display 31 hours? there's only 24 hours in a day EDIT: and another error, if the user have never logged in... then it will echo NOW instead of never Link to comment https://forums.phpfreaks.com/topic/156437-solved-help-with-this-please/#findComment-823699 Share on other sites More sharing options...
Ken2k7 Posted May 1, 2009 Share Posted May 1, 2009 You forgot modulo in hour and possibly. As for the other error, not my problem. Link to comment https://forums.phpfreaks.com/topic/156437-solved-help-with-this-please/#findComment-823717 Share on other sites More sharing options...
seany123 Posted May 1, 2009 Author Share Posted May 1, 2009 You forgot modulo in hour and possibly. As for the other error, not my problem. modulo?? Link to comment https://forums.phpfreaks.com/topic/156437-solved-help-with-this-please/#findComment-823742 Share on other sites More sharing options...
Ken2k7 Posted May 1, 2009 Share Posted May 1, 2009 Google much? It's the '%' sign. If you don't know what that does, read it up. Link to comment https://forums.phpfreaks.com/topic/156437-solved-help-with-this-please/#findComment-823754 Share on other sites More sharing options...
seany123 Posted May 3, 2009 Author Share Posted May 3, 2009 a problem is for some reason the second i log in, it starts going up, even when i am still actively clicking links and refreshing pages etc. Link to comment https://forums.phpfreaks.com/topic/156437-solved-help-with-this-please/#findComment-824821 Share on other sites More sharing options...
seany123 Posted May 3, 2009 Author Share Posted May 3, 2009 ive tried editing it about but im still getting the same issue. Link to comment https://forums.phpfreaks.com/topic/156437-solved-help-with-this-please/#findComment-824904 Share on other sites More sharing options...
Ken2k7 Posted May 3, 2009 Share Posted May 3, 2009 a problem is for some reason the second i log in, it starts going up, even when i am still actively clicking links and refreshing pages etc. Well that's what it should do. The function is called timeSince, so it only makes sense for it to go up. Link to comment https://forums.phpfreaks.com/topic/156437-solved-help-with-this-please/#findComment-824961 Share on other sites More sharing options...
seany123 Posted May 3, 2009 Author Share Posted May 3, 2009 right so what I need to do it have a query in a functions page which is called on every page... to set last_active to time() is that right? that way, the time will go up from the no pages have been loaded. Link to comment https://forums.phpfreaks.com/topic/156437-solved-help-with-this-please/#findComment-825021 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.