If Statement中的错误逻辑? [英] Wrong logic in If Statement?
本文介绍了If Statement中的错误逻辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ repeat_times = mysql_real_escape_string($ repeat_times);
$repeat_times = mysql_real_escape_string($repeat_times);
$result = mysql_query("SELECT `code`,`datetime` FROM `fc` ORDER by datetime desc LIMIT 25") or die(mysql_error());
$output .="";
$seconds = time() - strtotime($fetch_array["datetime"]);
if($seconds < 60)
$interval = "$seconds seconds";
else
if($seconds < 3600)
$interval = floor($seconds / 60) . " minutes";
else
if($seconds < 86400)
$interval = floor($seconds / 3600) . " hours";
else
$interval = floor($seconds / 86400) . " days";
while ($fetch_array = mysql_fetch_array($result)) {
$fetch_array["code"] = htmlentities($fetch_array["code"]);
$output .= "<li><a href=\"http://www.***.com/code=" . htmlspecialchars(urlencode($fetch_array["code"])) . "\" target=\"_blank\">" . htmlspecialchars($fetch_array["code"]) . "</a> (" . $interval . ") ago.</li>";
}
$output .="";
return $output;
为什么这个返回janice(14461天)而不是janice(15分钟前)
Why is this returning janice (14461 days) instead of janice (15 minutes ago)
日期时间函数表在我的表中有DATETIME类型,因此它返回日期的完整字符串。
The datetime function table has the DATETIME type in my table so it's returning a full string for the date.
推荐答案
时间计算代码应该进入while循环,因为你想在每个记录的基础上计算时间(它指的是$ fetch_array,它仅作为while循环的一部分被检索) )
The time calculation code should go inside the while loop, since you want to calculate the time on a per-record basis (that and it's referring to $fetch_array, which is only retrieved as part of the while loop)
这篇关于If Statement中的错误逻辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文