douya5331 2011-06-29 08:25
浏览 49
已采纳

jQuery Countdown使用PHP和MySQL

The idea: To create a countdown to show days or hours left until some event (no minutes or seconds are required)...

I have MySQL database which stores data used by countdown: id, date & description. I have a PHP file to get it all from database and output it into HTML

How it looks:

HTML Output:

<span>2 Days</span> Until Some Event!

PHP Code:

$result = mysql_query("SELECT * FROM countdowns ORDER BY id DESC",$connect);
while($myrow = mysql_fetch_assoc($result))
{
    echo "<div class=\"countdown\">";
        echo "<span>";
            echo $myrow['date'];
        echo "</span> ";
        echo $myrow['description'];
    echo "</div>";

So I want 'span' to dispaly days OR hours and rest will be description pulled from the database.

The problem: I want it to display ONLY days if hours are greater than 48 or ONLY hours if there are less than 48 hours left.

So it should look like:

5 Days Until Some Event! (There are more than 48 hours left)

OR

5 Hours Until Some Event! (There are obviously less than 48 hours left)

Why I need jQuery for this is because the page on which this countdown will be shown, will be active for days without reloading, so I need it to be dynamic...

I hope you can understand what I mean and probably could help me, thank you very much in advance!

Andrew Badger

  • 写回答

1条回答 默认 最新

  • dongxian8858 2011-06-29 08:36
    关注

    Maybe you could use a plugin like timeago and change it so that instead of writing the time eladsed from a timestamp it shows the time missing to a timestamp.

    EDIT - maybe you don't need to change any part of the code but just set this settings

    jQuery.timeago.settings.allowFuture = true;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元