PHP查詢分頁的實(shí)現(xiàn)代碼
本文實(shí)例為大家分享了PHP查詢分頁的具體代碼,后端基于thinkphp框架,供大家參考,具體內(nèi)容如下
前端需要dataTables插件:傳送門下載地址
HTML代碼
第一步引入插件
<!-- DataTables CSS --> <link rel="stylesheet" type="text/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>發(fā)布時間</th>
<th>發(fā)布IP</th>
<th>公告內(nèi)容</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');//實(shí)例化dbNotice對象
$count = $dbNotice->count();// 查詢滿足要求的總記錄數(shù)
$Page = new \Think\Page($count,$count);// 實(shí)例化分頁類 傳入總記錄數(shù)和每頁顯示的記錄數(shù)(全部記錄)
$data = $dbNotice->order('create_time')->limit($Page->firstRow.','.$Page->listRows)->select();//獲得所有記錄
$this->assign('notice',$data);//傳給模板
$this->show();
}
效果

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
laravel數(shù)據(jù)庫查詢結(jié)果自動轉(zhuǎn)數(shù)組修改實(shí)例
這篇文章主要介紹了laravel數(shù)據(jù)庫查詢結(jié)果自動轉(zhuǎn)數(shù)組修改實(shí)例,有需要的同學(xué)可以借鑒參考下2021-02-02
PHP開發(fā)框架kohana3 自定義路由設(shè)置示例
這篇文章主要介紹了PHP開發(fā)框架kohana3 自定義路由設(shè)置示例,kohana是一個純PHP5的開發(fā)框架,需要的朋友可以參考下2014-07-07
Laravel訪問出錯提示:`Warning: require(/vendor/autoload.php): faile
這篇文章主要介紹了Laravel訪問出錯提示:`Warning: require(/vendor/autoload.php): failed to open stream: No such file or di解決方法,涉及Laravel框架相關(guān)配置與安裝操作技巧,需要的朋友可以參考下2019-04-04
destoon文章模塊調(diào)用企業(yè)會員資料的方法
這篇文章主要介紹了destoon文章模塊調(diào)用企業(yè)會員資料的方法,非常實(shí)用的一個技巧,需要的朋友可以參考下2014-08-08
Yii2中設(shè)置與獲取別名的函數(shù)(setAlias和getAlias)用法分析
這篇文章主要介紹了Yii2中設(shè)置與獲取別名的函數(shù)(setAlias和getAlias)用法,較為詳細(xì)的分析了別名的概念、用法及Yii中設(shè)置與獲取別名的具體實(shí)現(xiàn)方法,需要的朋友可以參考下2016-07-07
php實(shí)現(xiàn)的一個很好用HTML解析器類可用于采集數(shù)據(jù)
下面就是這個 HTML解析類及用法,下面的功能是采集www.opendir.cn這個網(wǎng)站的百度收錄數(shù)據(jù),需要的朋友可以測試下2013-09-09
Laravel 之url參數(shù),獲取路由參數(shù)的例子
今天小編就為大家分享一篇Laravel 之url參數(shù),獲取路由參數(shù)的例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10
phpstorm配置php運(yùn)行環(huán)境的詳細(xì)步驟
這篇文章主要介紹了phpstorm配置php運(yùn)行環(huán)境的詳細(xì)步驟,首先安裝phpstrom,按照提示的步驟一步一步來就行,文中給大家介紹了phpstorm的簡單配置,需要的朋友可以參考下2023-09-09

