简体   繁体   English

插入新记录时如何自动刷新数据表?

[英]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.

相关问题 仅在插入或更新新数据时自动刷新/加载数据 - Auto refresh/load data only if new data inserted or updated 在服务器上插入记录后,EXTJS中的自动刷新网格 - Auto Refresh Grid in EXTJS after a record is Inserted on server 使用 jquery 插入相同记录时如何更新表 - How to update the table when same record is inserted using jquery 使用jquery和ajax插入相同记录时如何更新表 - How to update the table when same record is inserted using jquery and ajax 如何检查新数据是否已插入到mysql表中 - how to check whether new data has been inserted in mysql table 如何在Meteor中的集合(cursor.observeChanges)中插入新记录时播放音频 - How to play an audio to notify when new record is inserted in collection(cursor.observeChanges) in Meteor 使用node js和socket.io在mysql数据库中插入新记录时如何通知和更新客户端 - How to inform and update a client when a new record inserted in mysql database using node js and socket.io 新用户上线时自动刷新 - Auto refresh when new user comes online 创建记录后刷新表中的数据 - Refresh data in table after creating a record 仅当使用AngularJS从服务器中找到新数据时才自动刷新数据 - Auto refresh data only when new data is found from the server with AngularJS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM