首页 > 解决方案 > codeigniter 和 ajax 中的计时器

问题描述

我需要在 codeigniter 、 mysql 和 ajax 中使用计时器,因为天数来自每个产品的数据库。

<td id="timer"><?=$data['auction_end_time']?></td>

数据在几天内来自数据库,我想显示计时器。这是我的网站的链接,你可以在这里看到

请指导我...!

标签: jquerymysqlcodeignitertimer

解决方案


假设我们有以下 php 函数(这可以改进)

function auction_end_time($future_date) {

    $now = new DateTime();
    $future_date = new DateTime($future_date);

    if($future_date <= $now)
        return 'This offer has expired!';

    $interval = $future_date->diff($now);

   return $interval->format("%a days %h:%i:%s");
}

在你的 html 代码中

<td id="timer"><?=auction_end_time($data['auction_end_time'])?></td>

该解决方案是静态的。对于动态倒计时,您可以使用 jquery 插件,我找到了这个jQuery.countdown 插件

请参阅jsfiddle.net上的示例


推荐阅读