简体   繁体   English

PHP-MySQL反向计数器FlipClock

[英]Reverse counter FlipClock with PHP-MySQL

I want to use flipclock for the reverse counter. 我想将flipclock用于反向计数器。 The timer should start from hh:mm:ss (eg, 19:40:46) to 00:00:00. 计时器应从hh:mm:ss(例如19:40:46)开始到00:00:00。

Below is the code 下面是代码

var clock;

$(document).ready(function() {

    // Grab the current date
    var currentDate = new Date();

    // Set some date in the future. In this case, it's always Jan 1
    var futureDate  = new Date(currentDate.getFullYear() + 1, 0, 1);

    // Calculate the difference in seconds between the future and current date
    var diff = futureDate.getTime() / 1000 - currentDate.getTime() / 1000;

    // Instantiate a coutdown FlipClock
    clock = $('.dw_clock').FlipClock(diff, {
        clockFace: 'DailyCounter',
        countdown: true,
        showSeconds: true
    }); 
});

I don't want the date. 我不要约会 Also, the time values should get fetched from MySQL and are different for different users when they log in. From PHP-MySQL, I have: 另外,时间值应该从MySQL获取,并且对于不同的用户来说,登录时的时间值是不同的。从PHP-MySQL,我有:

function timeToPlay(&$smarty){

    $sqlStr = "select timediff('24:00:00', time(taken_on)) as timeRemaining,
            hour(timediff('24:00:00', time(taken_on))) as hour,
            minute(timediff('24:00:00', time(taken_on))) as minute,
            second(timediff('24:00:00', time(taken_on))) as second
        FROM profile_sicc_exer_score where user_id=".$_SESSION['user_id']."
        order by id desc limit 1";

    $sqlQuery = mysql_query($sqlStr) or die(mysql_error()."<hr>".$sqlStr);

    if ( mysql_num_rows($sqlQuery) ) {

        $timeToPlayNext = mysql_fetch_assoc($sqlQuery);

        $smarty->assign("timeRemaining",$timeToPlayNext['timeRemaining']);
        $smarty->assign("hour",$timeToPlayNext['hour']);
        $smarty->assign("minute",$timeToPlayNext['minute']);
        $smarty->assign("second",$timeToPlayNext['second']);

    }
}

From the above code, I get the values of (example) 从上面的代码中,我得到了(示例)的值

  1. $timeRemaining = 19:40:46 $ timeRemaining = 19:40:46
  2. $hour = 19 $小时= 19
  3. $minute = 40 每分钟= 40
  4. $second = 46 $ second = 46

How do I use the values in the above Flipclock code which is javascript/jquery... 如何使用上述Flipclock代码中的javascript / jquery中的值...

For flipClock, you have to change the clockFace to "HourlyCounter", so it doesn't show the date. 对于flipClock,您必须将clockFace更改为“ HourlyCounter”,因此它不显示日期。

After that, having the php variables, you can "echo" them into the javascript code, for example, at the end of the webpage, you can put: 之后,有了php变量,您可以将它们“回显”到javascript代码中,例如,在网页末尾,您可以输入:

<script>
clock.setTime(<?php echo $hour*3600+$minute*60+$second; ?>);
</script>

You can always put it in an "onload" function or something like that, but it should work fine with that. 您始终可以将其放在“ onload”函数或类似的函数中,但应该可以正常工作。

You didn't left any details about the actual html page where the counter is showing, so I can't help you further this. 您没有留下关于计数器所显示的实际html页面的任何详细信息,所以我无法帮助您进一步进行此操作。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM