Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 管理分页-从何处开始?_Php_Adminlte - Fatal编程技术网

Php 管理分页-从何处开始?

Php 管理分页-从何处开始?,php,adminlte,Php,Adminlte,我正在使用AdminLTE模板和Booststrap 3在PHP PDO中构建一个web数据库应用程序。 我需要将分页添加到我的应用程序中(因为我有大量记录),并且每页限制为25条记录。我对编程相当陌生,不知道从哪里开始。任何帮助都将不胜感激 <?php $content = '<div class="row"> <div class="col-xs-12"> <div class="box

我正在使用AdminLTE模板和Booststrap 3在PHP PDO中构建一个web数据库应用程序。 我需要将分页添加到我的应用程序中(因为我有大量记录),并且每页限制为25条记录。我对编程相当陌生,不知道从哪里开始。任何帮助都将不胜感激

<?php
  $content = '<div class="row">
                <div class="col-xs-12">
                <div class="box box-danger">
                  <div class="box-header">
                    <h3 class="box-title">Members List</h3>
                  </div>
                  <!-- /.box-header -->
                  <div class="box-body">
                    <table id="members" class="table table-bordered table-hover">
                      <thead>
                      <tr>
                        <th>Name</th>
                        <th>Residential Address</th>
                        <th>Mailing Address</th>
                        <th>Precinct</th>
                        <th>Age</th>
                        <th>Ethnicity</th>
                        <th>Gender</th>
                        <th>Party</th>
                        <th>Race</th>
                        <th>Phone Number</th>
                        <th>Action</th>
                      </tr>
                      </thead>
                      <tbody>
                      </tbody>
                      <tfoot>
                      <tr>
                        <th>Name</th>
                        <th>Residential Address</th>
                        <th>Mailing Address</th>
                        <th>Precinct</th>
                        <th>Age</th>
                        <th>Ethnicity</th>
                        <th>Gender</th>
                        <th>Party</th>
                        <th>Race</th>
                        <th>Phone Number</th>
                        <th>Action</th>
                      </tr>
                      </tfoot>
                    </table>
                  </div>
                  <!-- /.box-body -->
                </div>
                <!-- /.box -->
              </div>
            </div>';
  include('../master.php');
?>
<!-- page script -->
<script>
  $(document).ready(function(){
    $.ajax({
        type: "GET",
        url: "../api/member/read.php",
        dataType: 'json',
        success: function(data) {
            var response="";
            for(var user in data){
                response += "<tr>"+
                "<td>"+data[user].name+"</td>"+
                "<td>"+data[user].residential_address+"</td>"+
                "<td>"+data[user].mailing_address+"</td>"+
                "<td>"+data[user].precinct+"</td>"+
                "<td>"+data[user].age+"</td>"+
                "<td>"+data[user].ethnicity+"</td>"+
                "<td>"+data[user].gender+"</td>"+
                "<td>"+data[user].party+"</td>"+
                "<td>"+data[user].race+"</td>"+
                "<td>"+data[user].phone+"</td>"+
                "<td><a href='update.php?id="+data[user].id+"'>Edit</a> | <a href='#' onClick=Remove('"+data[user].id+"')>Remove</a></td>"+
                "</tr>";
            }
            $(response).appendTo($("#members"));
        }
    });
  });
  function Remove(id){
    var result = confirm("Are you sure you want to delete the selected member from the database?"); 
    if (result == true) { 
        $.ajax(
        {
            type: "POST",
            url: '../api/member/delete.php',
            dataType: 'json',
            data: {
                id: id
            },
            error: function (result) {
                alert(result.responseText);
            },
            success: function (result) {
                if (result['status'] == true) {
                    alert("The member was successfully removed from the database.");
                    window.location.href = '/ccrp/members';
                }
                else {
                    alert(result['message']);
                }
            }
        });
    }
  }
</script>

$(文档).ready(函数(){
$.ajax({
键入:“获取”,
url:“../api/member/read.php”,
数据类型:“json”,
成功:功能(数据){
var响应=”;
for(数据中的var用户){
响应+=“”+
“”+数据[用户]。名称+“”+
“”+数据[用户]。住宅地址+“”+
“”+数据[用户]。邮寄地址+“”+
“”+数据[用户]。辖区+“”+
“”+数据[用户]。年龄+“”+
“”+数据[用户]。种族+“”+
“”+数据[用户]。性别+“”+
“”+数据[用户]。参与方+“”+
“”+数据[用户]。比赛+“”+
“”+数据[用户]。电话+“”+
" | "+
"";
}
$(答复)。附件($(“#成员”);
}
});
});
函数删除(id){
var result=confirm(“是否确实要从数据库中删除所选成员?”);
如果(结果==true){
$.ajax(
{
类型:“POST”,
url:“../api/member/delete.php”,
数据类型:“json”,
数据:{
id:id
},
错误:函数(结果){
警报(result.responseText);
},
成功:功能(结果){
如果(结果['status']==true){
警报(“该成员已成功从数据库中删除”);
window.location.href='/ccrp/members';
}
否则{
警报(结果['message']);
}
}
});
}
}

您的数据在一个表中,我建议使用jquery类,它在表中内置了分页功能以及一个搜索框等。它还有一种您可以使用的样式。自己进行分页可能比使用这个类要困难得多,这在这里并不是真正需要回答的问题。为什么不使用PHP实现这一切,并在页面加载期间而不是之后构建表呢?您使用带有remove按钮的Ajax似乎是正确的,这与它的用途基本相同,但是以这种方式构建表对我来说很奇怪。而且,通常最好将HTML保留为HTML,而不是将其全部作为PHP进行响应。什么是
master.php
master.php
是描述整个应用程序布局的文件。所有项目文件都在引用它。它的所有代码都是HTML,而不是上面显示的从索引页获取内容的一行PHP代码。如果是我,我会将上面的所有代码都作为纯HTML(而不是PHP)。然后,在表的
tbody
中,将有一个PHP循环,它将填充表的所有行。此时,使用datatables非常简单,只需包含
.js
文件并使用
$('#members').DataTable()初始化它即可