如何解决DataTables 不能读取多个数据
我想问一下为什么DataTable在我的数据库中不能读取超过1个数据?由于我对数据表相对较新,我将不胜感激,谢谢。
如您所见,它只显示了 1 个条目中的 1 比 1。但如表所示,我有 5 个检索到的数据。
这是表格的代码。
<table class="table table-striped table-hover table-condense" id="tbl_research">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Resarch Title</th>
<th scope="col">Research Type</th>
<th scope="col">Research Author</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<tr>
<?PHP
include 'includes/connection_operation.PHP';
$sql = "SELECT * FROM tbl_repository";
$query = MysqLi_query($conn,$sql);
if($query)
{
while($row = MysqLi_fetch_assoc($query))
{
?>
<th><?PHP echo $row['ID']; ?></th>
<td><?PHP echo $row['research_title']; ?></td>
<td><?PHP echo $row['research_type']; ?></td>
<td><?PHP echo $row['research_author']; ?></td>
<td>
<input type="submit" name="submit" id="submit" value="View" class="btn btn-info"
data-toggle="modal" data-target="#viewResearchModal<?PHP echo $row["ID"];?>">
</td>
</tr>
</tbody>
<?PHP
include './helper/modal_viewresearch.PHP';
}
}
?>
</table>
<!DOCTYPE html>
<html>
<head>
<Meta charset="utf-8">
<Meta name="viewport" content="width=device-width,initial-scale=1.0">
<Meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>CRR | View Research</title>
<!-- Bootstrap CSS CDN -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<!-- Our Custom CSS -->
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.23/css/jquery.dataTables.min.css">
<!-- Font Awesome JS -->
<script defer src="https://use.fontawesome.com/releases/v5.0.13/js/solid.js" integrity="sha384-tzzSw1/Vo+0N5UhStP3bvwWPq+uvzCMfrN1fEFe+xBmv1C/AtVX5K0uZtmcHitFZ" crossorigin="anonymous"></script>
<script defer src="https://use.fontawesome.com/releases/v5.0.13/js/fontawesome.js" integrity="sha384-6OIrr52G08NpOFSZdxxz1xdNSndlD4vdcf/q2myIUVO0VsqaGHJsB0RaBE01VTOY" crossorigin="anonymous"></script>
</head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script>
<!-- Bootstrap JS -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.10.23/js/jquery.dataTables.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#sidebarCollapse').on('click',function () {
$('#sidebar').toggleClass('active');
});
});
</script>
<script>
$(document).ready(function() {
$(function () {
$('[data-toggle="popover"]').popover()
});
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
});
</script>
<script>
$(document).ready(function() {
$('#tbl_research').DataTable( {
} );
} );
</script>
</body>
</html>
解决方法
我不得不重新阅读我的整个代码 3 次,它只显示 1 的原因是 tbody 在循环内,所以它只看到 1。我不得不将它移到 while 循环之外,以便数据应该谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。