在Creating a timer with passing a PHP variable的扩展中,在将脚本添加到剩余的代码部分之后,我有一些跟进问题。似乎没有通过再次在那里发布来引起对问题的关注?希望对此事做一些澄清。
<html><head>
<?php $variable = "2013-12-01 17:00:00";?>
<script type="text/javascript">
function counter() {
var variable = <?php echo (json_encode($variable)) ?>;
var t = variable.split(/[- :]/);
var gametime = new Date(t[0], t[1]-1, t[2], t[3], t[4], t[5]);
var now = new Date();
var timeDiff = gametime.getTime() - now.getTime();
var timer = setTimeout('counter()');
if (timeDiff <= 0) {
clearTimeout(timer);
}
var seconds = Math.floor(timeDiff / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
hours %= 24;
minutes %= 60;
seconds %= 60;
document.getElementById("days").innerHTML = days;
document.getElementById("hours").innerHTML = hours;
document.getElementById("mins").innerHTML = minutes;
document.getElementById("sec").innerHTML = seconds;
}
</script>
</head>
<body>
<?php include 'header.html'; ?>
<div id="content">
<?php
$vip = "= '0'";
getOpenPicks($vip);
if (empty($rowset)) {
print "There are no open bets at the moment";
} else {
foreach ($rowset as $row) {?>
<form>
Time remaining: <label id=days></label>:<label id=hours></label>:<label id=mins></label>:<label id=sec></label><br>
<script type="text/javascript">counter();</script>
Match: <label for="home"><?php echo $row[1]?></label>
- <label for="away"><?php echo $row[2]?></label><br>
Bet: <label for="pick"><?php echo $row[3]?> </label><br>
Odds: <label for="pick"><?php echo $row[4]?></label><br>
Units: <label for="units"><?php echo $row[5]?></label><br>
</form><br>
<?php }
}?>
</div>
我对javascript很新,但是不可能在foreach循环中多次调用脚本吗?我问,因为我知道我的SQL查询中有几个不同的行,但计时器只显示在第一个?或者这可能是第一次没有传递的php变量的问题?