/ Published in: PHP
Taken from : http://www.phpfreechat.net/forum/viewtopic.php?pid=7587
See also this class : http://www.phpbuilder.com/snippet/download.php?type=snippet&id=2205
See also this class : http://www.phpbuilder.com/snippet/download.php?type=snippet&id=2205
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/**Function when($ts) takes timestamp on input and returns * human readable time difference. Example output: * I am running my script in 20 minute intervals to clear the * database and remove overhead. **/ function kiedy($ts) { if ($ts<60) // <1 minute return $ts; //." seconds ago"; elseif ($ts<60*60) // <1 hour elseif ($ts<60*60*2) // <2 hour return "60"; //"1 hour ago"; elseif ($ts<60*60*24) // <24 hours = 1 day elseif ($ts<60*60*24*2) // <2 days return "1 day ago"; elseif ($ts<60*60*24*7) // <7 days = 1 week elseif ($ts<60*60*24*30.5) // <30.5 days ~ 1 month elseif ($ts<60*60*24*365) // <365 days = 1 year else // more than 1 year }; $ts = $line['timestamp']; $result=kiedy($ts); if ($result > 20 ) { // ADJUST THIS TO CLEAR X MINUTES $SQL = "DELETE from chattable WHERE timestamp = '$ts'"; } } $SQL = 'OPTIMIZE TABLE chattable';