php - Displaying same time passed in while through time_passed function -
i'm doing while() , in use function display prettier "time since posted", reason, of results end in same "time passed" (the last result) when echoing out
only time become same, not other content. here's code, trimmed down bit:
<?php $result = $db->query("select * $dbboardname replyto = '' , hidden = '' order bump asc limit $pagenum, 20") or die($db->error); while($rowaaa = $result->fetch_assoc()){ $id = $rowaaa['id']; $textcontent = $rowaaa['textcontent']; $imageurl = $rowaaa['imageurl']; $name = $rowaaa['nameyes']; $timestamps = $rowaaa['timestamp']; $timestamps = time_passed($timestamps); $tripcode = $rowaaa['tripcode']; ?> <div class="post-index" data-postid="<?php echo($id); ?>" name="<?php echo($id); ?>" id="<?php echo($id); ?>"> <div class="image-container-index"> <?php if(!empty($imageurl)){ ?> <a href="post.php?id=<?php echo($id); ?>"><img src="<?php echo($imageurl); ?>" alt="image <?php echo($id); ?>" /></a> <?php }else{ ?> <a href="post.php?id=<?php echo($id); ?>"><img src="/images/noimage.png" alt="no image" /></a> <?php } ?> </div> <div class="post-info"> <span class="post-info-left"> #<a href="#" class="postid"><?php echo($id); ?></a> <?php if (!empty($name)){ echo(substr($name, 0, 8)); }else{ echo("norseman"); } ?> </span> <span class="post-info-right"> <?php echo($timestamps); ?> </span> <div class="clear"></div> </div> <div class="post-preview"> <?php echo(substr($textcontent, 0, 150)); ?> </div> </div> <?php } ?> <div class="clear"></div> and here time_passed() function:
function time_passed($datetime, $full = false) { $now = new datetime; $ago = new datetime($datetime); $diff = $now->diff($ago); $diff->w = floor($diff->d / 7); $diff->d -= $diff->w * 7; $string = array( 'y' => 'year', 'm' => 'month', 'w' => 'week', 'd' => 'day', 'h' => 'hour', 'i' => 'minute', 's' => 'second', ); foreach ($string $k => &$v) { if ($diff->$k) { $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : ''); } else { unset($string[$k]); } } if (!$full) $string = array_slice($string, 0, 1); return $string ? implode(', ', $string) . ' ago' : 'just now'; } so guess every new "while", edits of timestamps. don't know how fix this, considering string inside while() statement.
edit: noticed timestamp updated because altered bump row on every post each time new thread posted, way timestamps updated. fixed timestamp row now.
it looks time_passed routine expecting datetime - not timestamp, perhaps error.
function time_passed($datetime, $full = false) { try change line:
$ago = new datetime($datetime); to this:
$ago = new datetime(date('r',$datetime)); i hope helps.
Comments
Post a Comment