每個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循環? –