使用mysql进行多次倒计时

时间:2013-07-23 23:39:50

标签: php javascript

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

这是我的代码:

$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保存到数组中并使用到我的脚本中? 对于这种情况,我是怎么做到的?

由于

1 个答案:

答案 0 :(得分:0)

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

我如何发现倒计时结束和下次更新到我的数据库?

$ query3 =“select v.id,v.titulo,v.descricao,v.precoOriginal,v.desconto,v.dataFinal,v.estado,c.nome,i.nome,i.tipo from voucher as v                                   LEFT JOIN categoria as v on v.id_categoria = c.id.                                   左侧在i.id_Voucher = v.id上加入图像                                   在哪里c.nome =?                                   ORDER BY v.id DESC“;                         $ stmt3 = $ mybd-&gt; prepare($ query3);                         $ stmt3-&GT; bind_param( “S”,$猫);
                        $ stmt3-&GT;执行();                         $ stmt3-&gt; 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