我正在尝试使用 DataTables第二次在其他 PHP 页面,但我知道这个错误,
DataTables warning: Non-table node initialisation (TBODY).
我做错了什么?我在我的第一个 PHP 页面上尝试了这段代码,它工作正常。
这是我的表代码
<table class="table table-striped table-hover ">
<div class="row">
<div class="col-lg-12">
<div class="page-header">
<h1 id="tables">Admin's Accounts</h1>
</div>
<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#modal"><i class="zmdi zmdi-plus-circle zmdi-hc-2x"></i></button>
<table class="table table-striped table-hover ">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Contact</th>
<th>Email Address</th>
<th>Position</th>
<th>Option</th>
</tr>
</thead>
<tbody id="admin">
<?php
//set up mysql connection
mysql_connect("localhost", "root", "") or die(mysql_error());
//select database
mysql_select_db("brm_dbs") or die(mysql_error());
//select all records form tblmember table
$query = 'SELECT uid,name,contact,email,position FROM admin ORDER BY created_at DESC';
//execute the query using mysql_query
$result = mysql_query($query);
//then using while loop, it will display all the records inside the table
while ($row = mysql_fetch_array($result)) {
echo ' <tr> ';
echo ' <td> ';
echo $row['uid'];
echo ' <td> ';
echo $row['name'];
echo ' <td> ';
echo $row['contact'];
echo ' <td> ';
echo $row['email'];
echo ' <td> ';
echo $row['position'];
echo '<td>';
echo '<button type="button" class="btn btn-link" data-toggle="modal" data-target="#myModal'.$row['uid'].'"><i class="zmdi zmdi-plus-circle zmdi-hc-2x"></i></button>';
}
?>
</tbody>
</table>
</div>
</div>
</table>
我将其用于 JQUERY
<script src="https://cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.9/js/dataTables.bootstrap.min.js"></script>
<script>
$(document).ready(function() {
$('#admin').DataTable( {
"lengthMenu": [[5, 10, 25, -1], [5, 10, 25, "All"]]
});
} );
</script>
最佳答案
我收到错误:由于 DOM 中的另一个元素具有相同的“ID”,导致非表节点初始化
<table id="allProducts" class="table table-striped table-bordered" style="width:100%">
导航菜单中的 ID 相同
<a class="dropdown-item" href="#" id="allProducts" ><i class="fa fa-star"></i> All Products</a>
由于相同的 id 重复,我收到错误...:) 继续编码,享受美好时光
关于php - 数据表警告 : Non-table node initialisation (TBODY). PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32662307/