我想为表中的一列设置计时器,该列包含时间,我想为此列设置计时器。 此列的每个单元格都有一个特定的时间,如果时间是在该小时的20分钟之前的1小时,它应该显示一个弹出消息,该时间将结束。
下面是我的桌子:
列名:时差
<body>
<div class="card-body">
<table class="table">
<thead>
<tr>
<th>IdCard</th>
<th>Name</th>
<th>Company</th>
<th>Floors</th>
<th>Arrival</th>
<th>Departure</th>
<th>Time Difference</th>
</tr>
</thead>
<?php
include('includes/dbconnection.php');
$sql="SELECT *,
TIME_FORMAT(arrival, '%h:%i %p') AS arrival,
TIME_FORMAT(departure, '%h:%i %p') AS departure,
TIME_FORMAT(timediff(departure, arrival), '%H:%i') AS difftime
FROM master where Status = 'Pending'";
$query = $dbh -> prepare($sql);
$query->execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
$cnt=1;
if($query->rowCount() > 0) {
foreach($results as $row) {
?>
<tr>
<!-- <td><?php echo htmlentities($cnt);?></td>-->
<td><?php echo htmlentities($row->idcard);?></td>
<td><?php echo htmlentities($row->name);?></td>
<td><?php echo htmlentities($row->company);?></td>
<td><?php echo htmlentities($row->floors);?></td>
<td><?php echo htmlentities($row->arrival);?></td>
<td><?php echo htmlentities($row->departure);?></td>
<td><span style="color: red;"><?php echo htmlentities($row->difftime);?></span></td>
</tr>
<?php
$cnt=$cnt+1;
}
}
?>
</table>
</div>
</body>
表格图像
伊莉安娜,
查看这些答案如何用浏览器刷新PHP页面:
页面刷新后,当前代码将在最后一列“时间差”中显示新的时间差。
如果您仍然想显示弹出窗口,那么您需要使用一些Javascript在页面加载后显示弹出窗口,例如:
<body onload="showArrivingSoon()">
<!-- Your code ... -->
<script>
<?php
// Iterate through rows to produce string $arrivingSoonAsStringDelimitedByNewLine ...
?>
// Here the prepared string is printed to the page and initialize JS variable
var arrivingSoon = '<?php echo $arrivingSoonAsStringDelimitedByNewLine ?>';
function showArrivingSoon(arrivingSoon)
{
alert('Arriving soon:\n' + arrivingSoon);
}
</script>
</body>
迭代,计算和检查也可以在Javascript中完成。 要做到这一点,首先可以将数据行作为JSON从PHP传递到Javascript变量,然后迭代。