每个while循环运行它创建另一个表行和显示相关的数据的时候,我要显示在每行的列倒数计时器(展示时间流逝)。我的下面的脚本只运行一次。你有另一个想法如何做到这一点或做些什么?我在php while循环内写了下面的代码,但只运行一次。请帮助定时器倒计时只运行一次而不是循环之后?
<script>
counter=0;
</script>
<?php
$count=0;
while($rowp = $resultp->fetch_assoc()) {
echo <td><p id='demo",$count,"'></p></td>
?>
<script>
var countDownDate = new Date("<?php echo $enterytime1; ?>").getTime();
// Update the count down every 1 second
var x = setInterval(function() {
// Get todays date and time
var now = new Date().getTime();
// Find the distance between now an the count down date
var distance = now - countDownDate;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance/(1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24))/(1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60))/(1000 * 60));
var seconds = Math.floor((distance % (1000 * 60))/1000);
// Output the result in an element with id="demo"
document.getElementById("demo" + counter).innerHTML = hours + "h " + minutes + "m " + seconds + "s ";
// If the count down is over, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "EXPIRED";
}
}, 1000);
</script>
<?php }
?>
PHP veriable $ while循环运行每次enterytime1改变它的值。 –
我使用计数器变量等于0,而在循环开始但仍没有之前.. :( –
您正在打印整个脚本while循环? –