0

我有一个严重的问题,我无法解决。我需要进行多个倒计时,但在我的代码中,只有一个倒计时可以正常工作。我不明白为什么其他日期时间无法读取。我正在使用数据库来获取日期时间。

这是我的代码:

$stmt4 = $mybd->prepare($query3);
$stmt4->bind_param("s",$cat);                               
$stmt4->execute();
$stmt4->bind_result($idVoucher,$titulo,$descricao, $precoOriginal, $desconto,$data, $nome, $nomeImagem);
while($stmt4->fetch()){
     if($cat == $nome){
    if($idVoucher != $idVoucher2){

     echo "<input id='data2' type='hidden'  value='$data' />";

我使用这个脚本倒计时:

$(function(){

    var data = $('#data').val();
    var date_split = data.split(" ");
    var date = date_split[0];
    date = date.split("-");
    var time = date_split[1];
    time = time.split(":");

    var data1 = $('#data2').val();
    var date_split1 = data1.split(" ");
    var date1 = date_split1[0];
    date1 = date1.split("-");
    var time1 = date_split1[1];
    time1 = time1.split(":");

    var note = $('#note'),
        ts = new Date(date[0], date[1] - 01,date[2], time[0], time[1],time[2]),
        newYear = true;

    var note1 = $('#note1'),
        ts2 = new Date(date1[0], date1[1] - 01,date1[2], time1[0], time1[1],time1[2]),
        newYear = true;

    /*  if((new Date()) > ts){
        // The new year is here! Count towards something else.
        // Notice the *1000 at the end - time must be in milliseconds
        ts = (new Date()).getTime() + 10*24*60*60*1000;
        newYear = false;
    } */

    $('#endtime_1320').countdown({
        timestamp   : ts,
        callback    : function(days, hours, minutes, seconds){

            var message = "";

            message += days + " day" + ( days==1 ? '':'s' ) + ", ";
            message += hours + " hour" + ( hours==1 ? '':'s' ) + ", ";
            message += minutes + " minute" + ( minutes==1 ? '':'s' ) + " and ";
            message += seconds + " second" + ( seconds==1 ? '':'s' ) + " <br />";
        }
    });

    $('#endtime_1321').countdown({
        timestamp   : ts2,
        callback    : function(days, hours, minutes, seconds){

            var message = "";

            message += days + " day" + ( days==1 ? '':'s' ) + ", ";
            message += hours + " hour" + ( hours==1 ? '':'s' ) + ", ";
            message += minutes + " minute" + ( minutes==1 ? '':'s' ) + " and ";
            message += seconds + " second" + ( seconds==1 ? '':'s' ) + " <br />";
        }
    });
});

我该如何解决这个问题?将我的 dateTimes 保存到数组中并使用到我的脚本中?对于这种情况,我是怎么做到的?

谢谢

4

1 回答 1

0

我解决了我的问题......如果有人想使用,这里有代码。我使用了 Keith-Wood 倒计时,我的倒计时工作正常,但现在我想问另一个问题。倒计时结束后,我想更新到我的数据库中。

我如何发现倒计时完成和下次更新到我的数据库的时间?

$query3 = "从凭证中选择 v.id、v.titulo、v.descricao、v.precoOriginal、v.desconto、v.dataFinal、v.estado、c.nome、i.nome、i.tipo 作为 v LEFT JOIN categoria as c on v.id_categoria = c.id LEFT JOIN imagem as i on i.id_Voucher = v.id WHERE c.nome = ? ORDER BY v.id DESC"; $stmt3 = $mybd->prepare($query3); $stmt3->bind_param("s",$cat);
$stmt3->执行();$stmt3->bind_result($idVoucher,$titulo,$descricao, $precoOriginal, $desconto,$data,$estado, $nome, $nomeImagem,$tipo);

                    while($stmt3->fetch()){
                        if($nome == $cat){
                            if($idVoucher == $idVoucher2 && $estado == "ativo" && $tipo == "paginaPrincipal"){ ?>
                                    <h2><a href='./verOfertaCompra.php' ><?php echo $titulo ?></a></h2>
                                    <img class='imagem' src='./images/paginaPrincipal/<?php echo $nomeImagem; ?>' />
                                    <div class='info'>
                                        <div class='primeiro'>
                                        <input class='data<?php echo $idVoucher ?>' type='hidden'  value=<?php echo $data; ?> /><br/>
                                        <span style="font-size: 15px; font-weight: bold; margin-left:38px;">Este Voucher termina em </span><br/><br/>
                                        <div id="defaultCountdown" class="endtime<?php echo $idVoucher ?>"></div>
                                        <script type="text/javascript">
                                                $(function () {
                                                        var i = <?php echo $idVoucher ?>;
                                                        var dataVal = $(".data" + i.toString()).val();
                                                        var data = new Date(dataVal);
                                                        str = ".endtime"+i.toString();
                                                        $(str).countdown({until: data, format: 'dHMS'});
                                                    });
                                            </script>
                                        <?php                                               
于 2013-07-30T09:42:57.570 回答