[英]How to auto refresh data table when new record is inserted?
This is my code in data table fetching record: 这是我在数据表中获取记录的代码:
<section class="content">
<div class="row">
<div class="col-xs-12">
<div class="box">
<div class="box-header">
</div>
<div class="box-body">
<table id="example1" class="table table-bordered table-striped">
<thead>
<th>ID</th>
<th>Date</th>
<th>Name</th>
<th>Course</th>
<th>Purpose</th>
<th>Time-in</th>
<th>Time-out</th>
</thead>
<tbody>
<?php
include_once('Connection.php');
$sql = "SELECT * FROM attendance";
$result = mysqli_query($conn,$sql);
if ($result->num_rows > 0) {
while($row=mysqli_fetch_assoc($result)){
?>
<tr>
<td><?php echo $row['id']?></td>
<td><?php echo $row['date']?></td>
<td> <?php echo $row['name']?></td>
<td> <?php echo $row['course']?></td>
<td> <?php echo $row['purpose']?></td>
<td> <?php echo $row['time-in']?> </td>
<td>
<?php echo $row['time-out']?>
</td>
</tr>
<?php }}?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</section>
This is the javascript I use: 这是我使用的JavaScript:
<script src="bower_components/jquery/dist/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
setInterval(function () {
$('#box-body').load('data.php')
}, 2000);
});
</script>
Is there a way to auto refresh my data table when a new record is inserted? 插入新记录时,是否可以自动刷新数据表?
I tried echoing my data table in separate note pad and calling it by div in my javascript code but it does not work. 我尝试在单独的记事本中回显我的数据表,并在javascript代码中通过div调用它,但是它不起作用。
The table should be ajax-based if you want to update data without page refresh. 如果要更新数据而不刷新页面,则该表应基于Ajax。 You should use Jquery datatables server-side processing scenario to do so and Here's the complete method for it:
您应该使用Jquery datatables服务器端处理方案来执行此操作,这是它的完整方法:
https://datatables.net/examples/data_sources/server_side https://datatables.net/examples/data_sources/server_side
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.