【发布时间】:2014-10-27 00:48:30
【问题描述】:
我有一个包含多个字段的数据库表,我想用其中一个字段的整数值(以分钟为单位)进行倒计时。我如何使用这些值循环并显示 php 表中每一行的倒计时,并在需要时增加或减少过程中的时间?
Table.php
$sql="SELECT * FROM List where depName='Admisiones' and personStatus='Espera'";
$result=mysqli_query($con, $sql);
echo "<table border='15' cellpadding='10' cellspacing='3' bordercolor='00FF00'>
<tr>
<th>Turno</th>
<th>Nombre</th>
<th>Apellido</th>
<th>Segundo Apellido</th>
<th>Id Studiante</th>
<th>Status</th>
<th>Multiples Motivos</th>
<th>Tiempo Categoria</th>
<th>Tiempo Estimando</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['listNum'] . "</td>";
echo "<td>" . $row['personName'] . "</td>";
echo "<td>" . $row['personLast'] . "</td>";
echo "<td>" . $row['secondLast'] . "</td>";
echo "<td>" . $row['stuId'] . "</td>";
echo "<td>" . $row['personStatus'] . "</td>";
echo "<td>" . $row['manyMotive'] . "</td>";
echo "<td>" . $row['categoryTime'] . "</td>";
echo "<td>" . $row['estimatedTime']"</td>"; //USE THE CLOCK.PHP TO MAKE A COUNTDOWN FOR EACH ESTIMATED TIME.
//And have the ability to add or substrac time if needed.
echo "</tr>";
}
echo "</table>";
时钟.php
<script>
$('.countdown').each(function(){
var minutes = $(this).data('minutes');
var count = $(this); //countdown
var id = $(this).id;
$(this).countdown({
date : Date.now() + (minutes * 60000),
refresh : 1000
});
setInterval(function(count)
var minuteValue = count.text();
$.ajax({
url : 'TEST.php', //I created to make the test..
type : 'POST',
data : {currentMin : minuteValue, id:id},
success : function(response){
console.log(response);
}
});
});
});
TEST.php
<?php
include 'Connection.php';
$minValue = mysqli_real_escape_string($con, $_POST['minuteValue']);
$ID = mysqli_real_escape_string($con, $_POST['id']);
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
$sql ="Update List SET estimatedTime='$minValue' WHERE listNum='$ID'";
mysqli_query($con,$sql);
mysqli_close($con);
?>
【问题讨论】:
-
目前还不清楚您要做什么。您可以发布一些代码并澄清您的问题吗?
-
我拥有一切我只需要一种方法来实现它,因此时钟从
$row['categoryTime']获取值并在$row['estimatedTime']行中进行倒计时。 -
我不知道
$row['categoryTime']里面有什么,但是如果我正确理解了您的评论,您需要将其传递给您的 countDownTime 函数。所以它看起来像这样:<script>countDownTime(<?php echo $row['categoryTime']; ?>);</script>并使用该数据进行倒计时。我将脚本标签放在 php 标签之外,但如果更容易的话,你可以连接。仍然不能 100% 确定我是否完全理解你。 -
$row['categoryTime']内部是一个整数,例如 30。但是脚本函数没有参数...如果我这样做,我会工作吗?如果是这样,你能给我一个例子,我可以在函数中捕获那个 var。 -
很抱歉我缺乏知识,这是我第一次使用脚本。你能帮我把这两种语言混合起来让它工作吗:)
标签: javascript php html database