请问如何编辑此代码以显示最多包含200,000条记录的表的页面行选择器



下午好。

拜托,我需要你的帮助。我一直在做一个PHP MySQL Web项目,一切都很顺利。但是,我有一个似乎出现故障的数据表。

下面的代码是从这个站点 https://www.webslesson.info/2016/10/datatables-jquery-plugin-with-php-mysql-and-bootstrap.html 获取的数据表的代码。

数据表运行良好,对于少于 100 条记录的表,可以正确显示搜索框、页面导航和页面行选择器 (10、25、50、100(,但每次我将其连接到具有超过 200,000 条记录的表时,表出现故障。也就是说,它隐藏了搜索框,页面导航和页面行选择器,然后无休止地加载记录。

我现在的问题是如何使页面行选择器(10、25、50、100(正常工作,以便无论表中的记录数如何,页面都将加载默认的 10 条记录,在表底部显示搜索框和页面导航按钮

谢谢

<script>  
$(document).ready(function(){  
$('#employee_data').DataTable();  
});  
</script>
<?php  
$connect = mysqli_connect("localhost", "root", "", "blog_samples");  
$query ="SELECT * FROM tbl_employee ORDER BY ID DESC";  
$result = mysqli_query($connect, $query);  
?>  
<!DOCTYPE html>  
<html>  
<head>  
<title>Webslesson Tutorial | Datatables Jquery Plugin with Php MySql and Bootstrap</title>  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>  
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>  
<script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>            
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />  
</head>  
<body>  
<br /><br />  
<div class="container">  
<h3 align="center">Datatables Jquery Plugin with Php MySql and Bootstrap</h3>  
<br />  
<div class="table-responsive">  
<table id="employee_data" class="table table-striped table-bordered">  
<thead>  
<tr>  
							        <td>ID</td> 
<td>Name</td>  
<td>Address</td>  
<td>Gender</td>  
<td>Designation</td>  
<td>Age</td>  
									<td data-sortable="false">Action</td>  									
</tr>  
</thead>  
<?php  
while($row = mysqli_fetch_array($result))  
{  
echo '  
<tr>                                      
									<td>'.$row["tin_id"].'</td>  									
									<td>'.$row["name"].'</td>  
<td>'.$row["address"].'</td>  
<td>'.$row["gender"].'</td>  
<td>'.$row["designation"].'</td>  
<td>'.$row["age"].'</td>  
									<td>button</td>    									
</tr>  
';  
}  
?>  
</table>  
</div>  
</div>  
</body>  
</html>


这是一段美好的学习时光。

同时,我很抱歉没有回来发布这个问题的答案。

我能够通过创建自定义服务器端来解决它。代码太长,我无法粘贴到这里。但是,对于那些有问题的人,请访问此链接 https://www.webslesson.info/2017/01/php-pdo-ajax-crud-with-data-tables-and-bootstrap-modals.html。将代码复制到PHP编辑器中,重写代码以适合您的情况,您就可以开始了。

代码行很容易理解!

享受!

在按照我想要的方式添加带有按钮的服务器端的所有努力之后,我不能,所以我求助于使用这个 PHP-CODEIGNITER-DATATABLE-SERVERSIDE-CRUD-AJAX 如链接所示 https://github.com/ahmadsolehin/PHP-CODEIGNITER-DATATABLE-SERVERSIDE-CRUD-AJAX。

请注意,在我之前的表格中添加服务器端 ajax 代码想要主要问题。主要问题是在旁边添加按钮。我不能那样做,因此需要改变。

您可以下载它,进行一些调整并使其运行。它很好地运行了我的 300,000 条记录,我对此感到满意。

要将 100、250、500、1000 等值的页面行选择器添加到我的数据表中,我添加了以下代码行:

**"aLengthMenu": [[10, 50, 100, 250, 500, 1000], [100, 250, 500, 1000]],
"iDisplayLength": 10**

到我的脚本。"iDisplayLength":100将是默认值

<script>  
$(document).ready(function(){  
$('#employee_data').DataTable();
**"aLengthMenu": [[10, 50, 100, 250, 500, 1000], [10, 50, 100, 250, 500, 1000]],
"iDisplayLength": 10**
});  
</script> 

最新更新