1
我面臨的問題,顯示最新評論當我評論和1小時後,我看到輸出是「剛纔」,但我想顯示1小時去和顯示最近一次 如何顯示顯示最近的日期和時間的評論在php
請幫我在這種情況下
這裏所有的意見是我的代碼:
$comments = mysqli_query($conn, "SELECT * FROM `store_review` WHERE store_id = '$id1' ORDER BY review_date DESC ");
$new_result1 = mysqli_num_rows($comments);
$time = $row['review_date']." ".$row['review_time'];
<div class="review-block-date"><?php echo $time; ?><br/><?php echo ago($time); ?></div>
這裏是我的功能:
<?php
function ago($mytime)
{
$time_ago1 = strtotime($mytime);
$cur_time = time();
$time_elapsed = $cur_time - $time_ago1;
$seconds = $time_elapsed ;
$minutes = round($time_elapsed/60);
$hours = round($time_elapsed/3600);
$days = round($time_elapsed/86400);
$weeks = round($time_elapsed/604800);
$months = round($time_elapsed/2600640);
$years = round($time_elapsed/31207680);
// Seconds
if($seconds <= 60)
{
$post_time = "just now";
}
//Minutes
else if($minutes <=60)
{
if($minutes==1)
{
$post_time = "1 minute ago";
}
else
{
$post_time = "$minutes minutes ago";
}
}
//Hours
else if($hours <=24)
{
if($hours==1)
{
$post_time = "1 hrs ago";
}
else
{
$post_time = "$hours hrs ago";
}
}
//Days
else if($days <= 7)
{
if($days==1)
{
$post_time = "yesterday";
}
else
{
$post_time = "$days days ago";
}
}
//Weeks
else if($weeks <= 4.3)
{
if($weeks==1)
{
$post_time = "1 week ago";
}
else
{
$post_time = "$weeks weeks ago";
}
}
//Months
else if($months <=12)
{
if($months==1)
{
$post_time = "1 month ago";
}else{
$post_time = "$months months ago";
}
}
//Years
else
{
if($years==1)
{
$post_time = "1 year ago";
}
else
{
$post_time = "$years years ago";
}
}
return $post_time;
}?>
@siddartha esunuri。感謝您的幫助:) –
然後批准我的答案@HardChapla –