Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/478.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
多个拍卖项目的javascript计时器不适用于php_Javascript_Php_Mysql - Fatal编程技术网

多个拍卖项目的javascript计时器不适用于php

多个拍卖项目的javascript计时器不适用于php,javascript,php,mysql,Javascript,Php,Mysql,我正在尝试为在线拍卖项目实现一个倒计时,但它只对显示的一个项目有效。代码如下: <?php $result=mysql_query("select * from `date`")or die(mysql_error()); while($row=mysql_fetch_array($result)) { $then = $row['date']; $now = time(); $thenTimestamp = strtotime($then) + strtotime($now); $

我正在尝试为在线拍卖项目实现一个倒计时,但它只对显示的一个项目有效。代码如下:

 <?php
 $result=mysql_query("select * from `date`")or die(mysql_error());

while($row=mysql_fetch_array($result))
{
$then = $row['date'];
$now = time();
$thenTimestamp = strtotime($then) + strtotime($now);
$difference = $thenTimestamp - $now;
echo '<script type="text/javascript">

var seconds ='.$difference.';
function secondPassed() {
var hours=Math.round(seconds / 3600);
var minutes = Math.round(((seconds - 30)/60)%60);
var remainingSeconds = seconds % 60;

document.getElementById("countdown").innerHTML = hours+ ":"+ minutes + ":" +   remainingSeconds;

if (seconds == 0) {
  //  clearInterval(countdownTimer);
   document.getElementById("countdown").innerHTML = "Buzz Buzz";
} else {
    seconds--;
}
}
setInterval("secondPassed()", 1000);
  </script>
 <body>
 <span id="countdown"></span>
</body>';
}
?>

我必须在明天之前提交我的在线拍卖项目。所以,我需要解决方案。请帮帮我。
提前谢谢

你的问题/问题?以上脚本作品非常适合一次拍卖。如果我放置了多个拍卖,它只显示最后添加的拍卖的计时器。不是所有的吗?简单地说,你必须将每个拍卖放在单独的HTML元素中,并将你的代码封装在一个函数中,该函数使用该元素id或类名来运行计数器。你能给出一个演示吗?我试过上面的代码,但它只适用于一次拍卖。