>  기사  >  백엔드 개발  >  PHP에서 쿼리 페이징을 구현하는 방법

PHP에서 쿼리 페이징을 구현하는 방법

墨辰丷
墨辰丷원래의
2018-05-21 15:57:221456검색

이 기사에서는 주로 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 () {
  $(&#39;#table_id_example&#39;).DataTable();
 } );
 </script>

PHP 코드

 public 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를 추가하는 것입니다.

관련 추천:

PHP 쿼리 페이징 구현 방법

php쿼리 페이지 매김code

PHP 구현 쿼리 페이지 매김코드 예제

위 내용은 PHP에서 쿼리 페이징을 구현하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.