NSW42 Posted April 18, 2011 Share Posted April 18, 2011 I have a script for members to comment, how it works is they post a comment and the time is inserted, kinda like facebook, so it says a few secs ago mins ago hrs ago days etc, but the issue is that once the time hits 1hr it reverts back to a few secs ago and wont change again, I haven't posted the script yet, but just putting a feeler out to see if there maybe a simple answer to this. Thanks Quote Link to comment Share on other sites More sharing options...
requinix Posted April 18, 2011 Share Posted April 18, 2011 Sounds like all you have to do is add a condition to deal with a time>=an hour. Quote Link to comment Share on other sites More sharing options...
NSW42 Posted April 18, 2011 Author Share Posted April 18, 2011 Script is below if you or anyone can see where the issue is thanks. <?php ob_start("ob_gzhandler"); include('db-conn.php'); $displaynickname = $_SESSION["member_id"]; $sqlnick = mysql_query("SELECT * FROM members WHERE member_id = '$displaynickname'") OR DIE("Sorry there is a mysql error."); $rownick = mysql_fetch_array($sqlnick); $nickdoname = $rownick[member_id]; ?> <?php function checkValues($value) { $value = trim($value); if (get_magic_quotes_gpc()) { $value = stripslashes($value); } $value = strtr($value,array_flip(get_html_translation_table(HTML_ENTITIES))); $value = strip_tags($value); $value = mysql_real_escape_string($value); $value = htmlspecialchars ($value); return $value; } function clickable_link($text = '') { $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text); $ret = ' ' . $text; $ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret); $ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret); $ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret); $ret = substr($ret, 1); return $ret; } $next_records = 10; $show_more_button = 0; if(checkValues($_REQUEST['value'])) { $userip = $_SESSION["member_id"]; echo "INSERT INTO facebook_posts (post,f_name,userip,date_created) VALUES('".checkValues($_REQUEST['value'])."','".$nickdoname."','".$userip."','".strtotime(date("Y-m-d H:i:s"))."')"; mysql_query("INSERT INTO facebook_posts (post,f_name,userip,date_created) VALUES('".checkValues($_REQUEST['value'])."','".$nickdoname."','".$userip."','".strtotime(date("Y-m-d H:i:s"))."')"); $result = mysql_query("SELECT *, UNIX_TIMESTAMP() - date_created AS TimeSpent FROM facebook_posts order by p_id desc limit 1"); } elseif($_REQUEST['show_more_post']) // more posting paging { $next_records = $_REQUEST['show_more_post'] + 10; $result = mysql_query("SELECT *, UNIX_TIMESTAMP() - date_created AS TimeSpent FROM facebook_posts order by p_id desc limit ".$_REQUEST['show_more_post'].", 10"); $check_res = mysql_query("SELECT * FROM facebook_posts order by p_id desc limit ".$next_records.", 10"); $show_more_button = 0; // button in the end $check_result = mysql_num_rows(@$check_res); if($check_result > 0) { $show_more_button = 1; } } else { $show_more_button = 1; $result = mysql_query("SELECT *, UNIX_TIMESTAMP() - date_created AS TimeSpent FROM facebook_posts order by p_id desc limit 0,10"); } while ($row = mysql_fetch_array($result)) { $comments = mysql_query("SELECT *, UNIX_TIMESTAMP() - date_created AS CommentTimeSpent FROM facebook_posts_comments where post_id = ".$row['p_id']." order by c_id asc"); ?> <div class="friends_area" id="record-<?php echo $row['p_id']?>"> <?php $gogetname = $row['f_name']; $sqlgonick = mysql_query("SELECT * FROM members WHERE member_id = '$gogetname'") OR DIE("Sorry there is a mysql error."); $rowgonick = mysql_fetch_array($sqlgonick); $gonickdoname = $rowgonick[display_name]; ?> <?php $sql="select * from photos where member_id = $gogetname and main_image='1'"; $res=mysql_query($sql); $num_rows=mysql_num_rows($res); if($num_rows==0) { $sql="select * from photos where member_id = $gogetname"; $res=mysql_query($sql); $data_set=mysql_fetch_array($res); } else { $sql="select * from photos where member_id = $gogetname and main_image='1'"; $res=mysql_query($sql); $data_set=mysql_fetch_array($res); } $postersdtartimg = $data_set["photo_url"]; ?> <a href="../view_profile.php?member_id=<?php echo $gogetname; ?>" target="_blank" border="0"><img src="../<?php echo $postersdtartimg;?>" width="60" style="float:left;" alt="" border="0" /></a> <label style="float:left" class="name"> <b><?php echo $gonickdoname;?></b> <br> <em><?php echo clickable_link($row['post']);?></em> <br clear="all" /> <span> <?php // echo strtotime($row['date_created'],"Y-m-d H:i:s"); $days = floor($row['TimeSpent'] / (60 * 60 * 24)); $remainder = $row['TimeSpent'] % (60 * 60 * 24); $hours = floor($remainder / (60 * 60)); $remainder = $remainder % (60 * 60); $minutes = floor($remainder / 60); $seconds = $remainder % 60; if($days > 0) echo date('F d Y', $row['date_created']); elseif($days == 0 && $hours == 0 && $minutes == 0) echo "few seconds ago"; elseif($days == 0 && $hours == 0) echo $minutes.' minutes ago'; else echo "few seconds ago"; ?> </span> <a href="javascript: void(0)" id="post_id<?php echo $row['p_id']?>" class="showCommentBox">Comments</a> </label> <?php $userip = $_SESSION["member_id"]; if($row['userip'] == $userip){?> <a href="#" class="delete"> Remove</a> <?php }?> <br clear="all" /> <div id="CommentPosted<?php echo $row['p_id']?>"> <?php $comment_num_row = mysql_num_rows(@$comments); if($comment_num_row > 0) { while ($rows = mysql_fetch_array($comments)) { $days2 = floor($rows['CommentTimeSpent'] / (60 * 60 * 24)); $remainder = $rows['CommentTimeSpent'] % (60 * 60 * 24); $hours = floor($remainder / (60 * 60)); $remainder = $remainder % (60 * 60); $minutes = floor($remainder / 60); $seconds = $remainder % 60; ?> <?php $getposternick = $rows['userip']; $sqlgetposternick = mysql_query("SELECT * FROM members WHERE member_id = '$getposternick'") OR DIE("Sorry there is a mysql error."); $rowgetposternick = mysql_fetch_array($sqlgetposternick); $showposternick = $rowgetposternick[display_name]; ?> <?php $sql="select * from photos where member_id = $getposternick and main_image='1'"; $res=mysql_query($sql); $num_rows=mysql_num_rows($res); if($num_rows==0) { $sql="select * from photos where member_id = $getposternick"; $res=mysql_query($sql); $data_set=mysql_fetch_array($res); } else { $sql="select * from photos where member_id = $getposternick and main_image='1'"; $res=mysql_query($sql); $data_set=mysql_fetch_array($res); } $posterimg = $data_set["photo_url"]; ?> <div class="commentPanel" id="record-<?php echo $rows['c_id'];?>" align="left"> <img src="../<?php echo $posterimg; ?>" width="25" class="CommentImg" style="float:left;" alt="" /> <label class="postedComments"> <font color="#6A6A72"><?php echo $showposternick; ?>:</font> <?php echo clickable_link($rows['comments']);?> </label> <br clear="all" /> <span style="margin-left:43px; color:#666666; font-size:11px"> <?php if($days2 > 0) echo date('F d Y', $rows['date_created']); elseif($days2 == 0 && $hours == 0 && $minutes == 0) echo "few seconds ago"; elseif($days2 == 0 && $hours == 0) echo $minutes.' minutes ago'; else echo "few seconds ago"; ?> </span> <?php $userip = $_SESSION["member_id"]; if($rows['userip'] == $userip){?> <a href="#" id="CID-<?php echo $rows['c_id'];?>" class="c_delete">Delete</a> <?php }?> </div> <?php }?> <?php }?> </div> <div class="commentBox" align="right" id="commentBox-<?php echo $row['p_id'];?>" <?php echo (($comment_num_row) ? '' :'style="display:none"')?>> <img src="send.gif" width="25" class="CommentImg" style="float:left;" alt="" /> <label id="record-<?php echo $row['p_id'];?>"> <textarea class="commentMark" id="commentMark-<?php echo $row['p_id'];?>" name="commentMark" cols="60"></textarea> </label> <br clear="all" /> <a id="SubmitComment" class="small button comment"> Comment</a> </div> </div> <?php } if($show_more_button == 1){?> <div id="bottomMoreButton"> <a id="more_<?php echo @$next_records?>" class="more_records" href="javascript: void(0)">Older Posts</a> </div> <?php }?> Quote Link to comment Share on other sites More sharing options...
requinix Posted April 19, 2011 Share Posted April 19, 2011 Take a look at if($days > 0) echo date('F d Y', $row['date_created']); elseif($days == 0 && $hours == 0 && $minutes == 0) echo "few seconds ago"; elseif($days == 0 && $hours == 0) echo $minutes.' minutes ago'; else echo "few seconds ago"; Quote Link to comment Share on other sites More sharing options...
NSW42 Posted April 19, 2011 Author Share Posted April 19, 2011 I have been actually and is something that isnt right in that part ? 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.