Home >Backend Development >PHP Tutorial >How to implement PHP query paging

How to implement PHP query paging

小云云
小云云Original
2018-03-21 14:37:252231browse

HTML code This article mainly shares with you the implementation method of PHP query paging. The back-end is based on the thinkphp framework and the front-end requires the dataTables plug-in. I hope everyone can do this.

The first step is to introduce the plug-in

6e0ab5260bbfb4e234e489c7a279f1a9
7cba2a50bf6e767b3464ea3ce82f67ad

806d635094af43168be10d116e5a5866
9db43f327d72a00d68f8f2b1094aa2022cacc6d41bbb37262a98f745aa00fbf0

10508be7474e9d9608f1b198851d0815
b86f069fc5dab7a4adba05c287456c872cacc6d41bbb37262a98f745aa00fbf0

The second step is to add

<table id="table_id_example" class="display">
   <thead>
   <tr>
      <th>ID</th>
      <th>发布时间</th>
      <th>发布IP</th>
      <th>公告内容</th>
   </tr>
   </thead>
   <tbody>
      <volist name="notice" id="vo">
         <tr>
            <td>{$vo.id}</td>
            <td>{$vo.create_time}</td>
            <td>{$vo.create_ip}</td>
            <td>{$vo.notice_content}</td>
         </tr>
      </volist>
   </tbody>
</table>

The third step is JS

3f1c4e4b6b16bbbd69b2ee476dc4f83a
    $(document).ready( function () {
        $('#table_id_example').DataTable();
    } );
   2cacc6d41bbb37262a98f745aa00fbf0

PHP code

ublic function gonggaochakan(){
    /* 公告查看
     */
    $dbNotice = M(&#39;notice&#39;);//实例化dbNotice对象
    $count      = $dbNotice->count();// 查询满足要求的总记录数
    $Page       = new \Think\Page($count,$count);// 实例化分页类 传入总记录数和每页显示的记录数(全部记录)
    $data = $dbNotice->order(&#39;create_time&#39;)->limit($Page->firstRow.&#39;,&#39;.$Page->listRows)->select();//获得所有记录
    $this->assign(&#39;notice&#39;,$data);//传给模板
    $this->show();
}

Effect

The above is the detailed content of How to implement PHP query paging. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn