我有一个 php 循环,用于从数据库中获取多个拍卖记录。作为拍卖的一部分,我想倒计时直到它结束。我最初有一个问题,只有第一条记录显示倒数计时器(工作)并确定这可能是因为我每次都给 jquery 选择器相同的 id。所以我改变了它,所以生成了一个新的 id 来给每个循环上的 div 和 jquery 函数。但是现在当我查看脚本的结果时,倒数计时器不会显示在任何表格行中。
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
$ID = $row['ID'];
$cdRand = '#row'.$ID;
$img = $row['img'];
$desc = $row['description'];
$name = $row['name'];
$owner = $row['owner'];
$cprice = $row['sprice'];
$iprice = $row['iprice'];
$incprice = $row['incprice'];
$etime = $row['etime'];
$nextBid = $cprice + $incprice;
$stmt2 = $pdo->prepare("SELECT * FROM user WHERE username = :username");
$stmt2->bindParam(":username", $owner,PDO::PARAM_STR);
$stmt2->execute();
$thisuser2 = $stmt2->fetch(PDO::FETCH_ASSOC);
$location = $thisuser2['location'];
echo'
<tr class="resultindex">
<td class="imgCol"><a href="displayAuct.php?id='.$ID.'"><img src="'.$img.'" alt="'.$name.'" /></a></td>
<td class="infoCol">
<div class="nameDiv">
<a class="nameLink" href="displayAuct.php?id='.$ID.'">'.$name.'</a><br/>
</div>
<div class="descDiv">
<span class="priceLabel2">'.$desc.'</span>
</div>
<div class="userdiv">
<span class="fromuser">Location: </span><br/>
<span class="location">'.$location.'</span>
</div>
</td>
<td style="width:1px; background-color:#330066;" ></td>
<td class="timerCol">
<div class="currentp" style="height: 50px;"><span class="priceLabel">Current Bid: </span><br/><span class="price1">$'.$cprice.'</span></div>
<div id="timeRow" style="height: 30px;">
<span class="timeleft">Time Left: </span>
</div>
<div id="'.$cdRand.'" style="height:80px;"></div>
<script type=text/javascript>
var timestamp = '. $etime * 1000 .';
var endTime = new Date();
endTime.setTime(timestamp);
$("'.$cdRand.'").countdown({until: endTime});
</script>
</td>
</tr>
';
我不知道为什么它不起作用,倒计时计时器是 keith woods 倒计时插件http://keith-wood.name/countdown.html,任何帮助将不胜感激。
干杯,邦迪