PHP时间以来不起作用

时间:2015-10-06 11:17:19

标签: php

我的PHP代码有问题 我试图创造一段时间(通知被发送)的东西,它不起作用。而且我不明白为什么......我在stackoverflow上搜索了我做错了什么

这是我的代码

$dbh = new PDO('mysql:host=xxx;dbname=xxx', 'xxx', 'xxx');
$SN = $dbh->prepare("SELECT * FROM notif WHERE send_to IN ('{$_SESSION['user_name']}') ORDER BY not_id DESC LIMIT 4");
$SN->execute();

$NN = $SN->rowCount();
if ($NN == 0)
{
    print("<br><div class=\"alert alert-danger\">Je hebt geen notificaties!</div>");
}
while ($row = $SN->fetch(PDO::FETCH_ASSOC))
{
    echo " <li>
          <i class='{$row['not_icon']}'></i>
           <div class='font-w600'>{$row['send_by']}</div>
            <div><a href='javascript:void(0)'>{$row['notif_text']}</a></div>
                            ";



$time = $row['date_send'];

}

echo 'event happened '.humanTiming($time).' ago';

function humanTiming ($time)
{

    $time = time() - $time; // to get the time since that moment
    $time = ($time<1)? 1 : $time;
    $tokens = array (
        31536000 => 'year',
        2592000 => 'month',
        604800 => 'week',
        86400 => 'day',
        3600 => 'hour',
        60 => 'minute',
        1 => 'second'
    );

    foreach ($tokens as $unit => $text) {
        if ($time < $unit) continue;
        $numberOfUnits = floor($time / $unit);
        return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
    }

}
$dbh = null;

这只输出&#34;事件发生在45年前&#34;在最后一次通知......

0 个答案:

没有答案