CodeIgniter分頁類pagination使用方法示例
本文實(shí)例講述了CodeIgniter分頁類pagination使用方法。分享給大家供大家參考,具體如下:
controller控制器(application/controller/page.php文件):
public function index()
{
$this->load->model ( 'home_model' , '' , TRUE);
$config= array();
$config['per_page'] = $this->per_page; //每頁顯示的數(shù)據(jù)數(shù)
$current_page = intval($this->input->get_post('per_page',true)); //獲取當(dāng)前分頁頁碼數(shù)
//page還原
if(0 == $current_page)
{
$current_page = 1;
}
$offset = ($current_page - 1 ) * $config['per_page']; //設(shè)置偏移量 限定 數(shù)據(jù)查詢 起始位置(從 $offset 條開始)
$result = $this->home_model->index($offset,$config['per_page'],$order='id desc');
$config['base_url'] = $this->config->item('base_url').'admin/home/index?';
$config['first_link'] = $this->first_link;//首頁
$config['prev_link'] = $this->prev_link;//上一頁
$config['next_link'] = $this->next_link;//下一頁
$config['last_link'] = $this->last_link;//尾頁
$config['total_rows'] = $result['total'];//總條數(shù)
$config['num_links'] = 3;//頁碼連接數(shù)
$config['use_page_numbers'] = TRUE;
$config['page_query_string'] = TRUE;
$this->load->library('pagination');//加載ci pagination類
$this->pagination->initialize($config);
$result = array(
'list' => $result['list'],
'total' => $result['total'],
'current_page' => $current_page,
'per_page' => $config['per_page'],
'page' => $this->pagination->create_links(),
);
$this->load->view ( 'admin/home' , $result );
}
model模型(application/model/home_model.php文件):
public function index($offset,$num,$order='id desc')
{
$query = $this->db->query( "SELECT Name_cn,Mall_type,create_time FROM smzdm_mall WHERE Is_deleted = 0 order by {$order} limit {$offset},{$num}");
return array(
'total' => $this->db->count_all('smzdm_mall',array('Is_deleted'=>'0')),
'list' => $query->result(),
);
}
更多關(guān)于CodeIgniter相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《codeigniter入門教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《php日期與時(shí)間用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家基于CodeIgniter框架的PHP程序設(shè)計(jì)有所幫助。
相關(guān)文章
Laravel 對某一列進(jìn)行篩選然后求和sum()的例子
今天小編就為大家分享一篇Laravel 對某一列進(jìn)行篩選然后求和sum()的例子,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10
PHP使用Face++接口開發(fā)微信公眾平臺人臉識別系統(tǒng)的方法
這篇文章主要介紹了PHP使用Face++接口開發(fā)微信公眾平臺人臉識別系統(tǒng)的方法,涉及微信公眾平臺相關(guān)接口的使用技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04
golang實(shí)現(xiàn)php里的serialize()和unserialize()序列和反序列方法詳解
這篇文章主要介紹了golang實(shí)現(xiàn)php里的serialize()和unserialize()序列和反序列方法詳解,需要的朋友可以參考下2018-10-10
詳解PHP中cookie和session的區(qū)別及cookie和session用法小結(jié)
這篇文章主要介紹了PHP中cookie和session的區(qū)別及cookie和session用法小結(jié)的相關(guān)資料,非常不錯(cuò)具有參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06
laravel框架使用FormRequest進(jìn)行表單驗(yàn)證,驗(yàn)證異常返回JSON操作示例
這篇文章主要介紹了laravel框架使用FormRequest進(jìn)行表單驗(yàn)證,驗(yàn)證異常返回JSON操作,涉及l(fā)aravel表單請求類的創(chuàng)建、使用及異常處理相關(guān)操作技巧,需要的朋友可以參考下2020-02-02

