我想在10分钟后为每个表行添加一个通知,
计数器的开始时间将基于数据库上的输入时间。
Sample Table
ID | Item | EntryTime | Status |
-------------------------------------------------------------
101 | Fries | 19:20:12 | Active |Alert Goes Here
102 | burger | 22:23:14 | Active |Alert Goes Here
if 101 timer is over 10 Minutes, an alert or notification would appear.
我需要你们的帮助,非常感谢,非常感激。
我可以在纯PHP中使用特定时间的页面刷新,
但是我认为这会消耗资源
这是一个丑陋的实现,但假设你可以处理编写一个addAlertToRow
函数…这至少会让你走上正确的轨道
<table>
<? foreach($rows as $row): ?>
<tr id="<?=$row['id'];?>">
<td><?=$row['id'];?></td>
...
<td><span class="alert"></span>
<script>
(function() {
var ten_minutes = 600000; //milliseconds
var now = <?=time() * 1000;?>;
var entryTime= <?php echo strtotime($entryTime)*1000; ?>;
var timeAgo = now - entryTime; //how long ago was the entry added
setTimeout(function() {
var row = document.getElementById('<?=$row['id'];?>');
addAlertToRow(row);
}, ten_minutes - timeAgo);
})();
</script>
</td>
</tr>
<? endforeach; ?>
</table>