php查詢分頁代碼

來源:互聯網
上載者:User
這篇文章主要為大家詳細介紹了PHP查詢分頁的實現代碼,具有一定的參考價值,感興趣的小夥伴們可以參考一下

本文執行個體為大家分享了PHP查詢分頁的具體代碼,後端基於thinkphp架構,供大家參考,具體內容如下

前端需要dataTables外掛程式:傳送門下載地址

HTML代碼

第一步引入外掛程式

<!-- DataTables CSS --><link rel="stylesheet" type="text/css" href="http://cdn.datatables.net/1.10.15/css/jquery.dataTables.css" rel="external nofollow" ><!-- jQuery --><script type="text/javascript" charset="utf8" src="http://code.jquery.com/jquery-1.10.2.min.js"></script><!-- DataTables --><script type="text/javascript" charset="utf8" src="http://cdn.datatables.net/1.10.15/js/jquery.dataTables.js"></script>

第二步添加

<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>

第三步JS

 <script> $(document).ready( function () {  $('#table_id_example').DataTable(); } ); </script>

PHP代碼

 public function gonggaochakan(){ /* 公告查看  */ $dbNotice = M('notice');//執行個體化dbNotice對象 $count  = $dbNotice->count();// 查詢滿足要求的總記錄數 $Page  = new \Think\Page($count,$count);// 執行個體化分頁類 傳入總記錄數和每頁顯示的記錄數(全部記錄) $data = $dbNotice->order('create_time')->limit($Page->firstRow.','.$Page->listRows)->select();//獲得所有記錄 $this->assign('notice',$data);//傳給模板 $this->show();}


效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.