sql >> Base de Datos >  >> RDS >> Mysql

cómo hacer un temporizador de cuenta regresiva para el sitio web de ofertas

cambie setTimeout con esto:

setTimeout(function(){countdown(theyear,themonth,theday,id);},1000)

puede hacer que su función jQuery funcione así:

jQuery.fn.countdown = function(yr,m,d){
   $that = $(this);
   theyear=yr;themonth=m;theday=d
   var today=new Date()
   var todayy=today.getYear()
   if (todayy < 1000)
      todayy+=1900
   var todaym=today.getMonth()
   var todayd=today.getDate()
   var todayh=today.getHours()
   var todaymin=today.getMinutes()
   var todaysec=today.getSeconds()
   var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
   futurestring=montharray[m-1]+" "+d+", "+yr
   dd=Date.parse(futurestring)-Date.parse(todaystring)
   dday=Math.floor(dd/(60*60*1000*24)*1)
   dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
   dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
   dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
   if(dday==0 && dhour==0 && dmin==0 && dsec==0){
      $that.val(current);
      return
   }
   else
     $that.val("Only "+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds   left "+before);
 setTimeout(function(){ $that.countdown(theyear,themonth,theday);},1000)
}

<?php 
include('../connection.php');
    $rs = mysql_query("select * from datepic") or die(mysql_error());

    if(mysql_num_rows($rs)){

        while($row = mysql_fetch_array($rs))
        {
            $date = str_replace('-',',',$row['date']);

            echo '<input type="text" id="'.$row['id'].'" size=80>';
            ?>
            <script>
                $("?php echo $row['id'] ?>").countdown(<?php echo $date?>);

            </script>


            <?php           

        }
    }

?>