jkewlo Posted July 8, 2009 Share Posted July 8, 2009 so i am trying to get time like twitter/facebook/myspace my problem is that it is posting the time/date of the current time/date I have 2 funtions one being time_since() and add_post() time_since() Time since is the function that returns year, day, minutes, seconds since. function time_since($time){ //The Output the time is used at $format = "F m, Y g:i a"; //Time presets for the lazy (Time goes by seconds) $timeyear = 365 * 24 * 60 * 60; $timemonth = 30 * 7 * 24 * 60 * 60; $timeweek = 7 * 24 * 60 * 60; $timeday = 24 * 60 * 60; $timehour = 60 * 60; $timemins = 60; $timeseconds = 1; //today's date $today = time(); //Get the time from today by minusing the time looked at by today's date $x = $today - $time; //These define the out put if($x >= $timeyear){$x = date($format, $x); $dformat=""; $pre ="On the date: "; }elseif($x >= $timemonth){$x = date($format, $x); $dformat=""; $pre ="On the date: "; }elseif($x >= $timeday){$x = round($x / $timeday); $dformat="days ago"; $pre ="About"; $x = round($x); }elseif($x >= $timehour){$x = round($x / $timehour); $dformat="hours ago"; $pre ="About"; }elseif($x >= $timemins){$x = round($x / $timemins); $dformat="minutes ago"; $pre ="About"; }elseif($x >= $timeseconds){$x = round($x / $timeseconds); $dformat="seconds ago"; $pre ="About"; } return $pre." ".$x." ".$dformat; } add_post() adds the post to the database. function add_post($userid, $body) { $body = str_replace("","<img src=\"img/smilehappy.png\">",$body); $body = str_replace("","<img src=\"img/smilesad.png\">",$body); $body = str_replace("X(","<img src=\"img/smilemad.png\">",$body); $body = str_replace("o.O","<img src=\"img/smileoO.png\">",$body); $body = str_replace("><","<img src=\"img/smilesquint.png\">",$body); $body = str_replace(">_<","<img src=\"img/smileninja.png\">",$body); $body = str_replace(":S","<img src=\"img/smilesick.png\">",$body); $body = str_replace("zZz","<img src=\"img/smileZz.png\">",$body); $body = str_replace("oO","<img src=\"img/smilepo.png\">",$body); $sql = "insert into posts (user_id, body, stamp) values ($userid, '" . mysql_real_escape_string($body) . "', now())"; $result = mysql_query($sql); } then profile.php I have called the function time_since() <?php $dateofpost = time_since($time); $posts = show_posts($_SESSION['userid'], $list['id']); if (count($posts)){ ?> <table border='0' cellspacing='0' cellpadding='0' > <?php foreach ($posts as $key => $list){ echo "<tr valign='top'>\n"; echo "<td><a href=\"/". $list['username'] ."\"><font color=black>".$list['username'] ."</font></a></td>\n"; echo "<td> <font color=black><strong>".$list['body'] ."</strong></font> <a href=\"remove.php?id=". $list['id'] ."\">Remove</a><br/>\n"; echo "<small> <font color=black>". $dateofpost ."</font></small></td>\n"; echo "</tr>\n"; } ?> </table> <?php }else{ ?> <p><b>You haven't posted anything yet!</b></p> <?php } ?> but it returns Grind3r | what are you thinking? On the date: July 07, 2009 7:42 pm and that updates when the time changes and I posted that yesterday at like 6:00 pm. anything anyone can do and or point me in the right direction Link to comment https://forums.phpfreaks.com/topic/165279-php-twitter-like-time/ Share on other sites More sharing options...
jkewlo Posted July 9, 2009 Author Share Posted July 9, 2009 no one care to take this on? Link to comment https://forums.phpfreaks.com/topic/165279-php-twitter-like-time/#findComment-871635 Share on other sites More sharing options...
jkewlo Posted July 9, 2009 Author Share Posted July 9, 2009 I want the time to print like posted x seconds ago. I have found some scripts but nothing showing how it is done. Link to comment https://forums.phpfreaks.com/topic/165279-php-twitter-like-time/#findComment-871682 Share on other sites More sharing options...
lore_lanu Posted July 9, 2009 Share Posted July 9, 2009 take a look at this site: http://aidanlister.com/2004/04/making-time-periods-readable/ Link to comment https://forums.phpfreaks.com/topic/165279-php-twitter-like-time/#findComment-871702 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.