Wrong logic in If Statement?
Posted
by Charles
on Stack Overflow
See other posts from Stack Overflow
or by Charles
Published on 2009-08-05T23:19:23Z
Indexed on
2010/05/12
23:44 UTC
Read the original article
Hit count: 216
$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;
Why is this returning janice (14461 days) instead of janice (15 minutes ago)
The datetime function table has the DATETIME type in my table so it's returning a full string for the date.
© Stack Overflow or respective owner