CodeIgniter分頁(yè)類(lèi)pagination使用方法示例
來(lái)源:易賢網(wǎng) 閱讀:1540 次 日期:2016-08-31 15:34:00
溫馨提示:易賢網(wǎng)小編為您整理了“CodeIgniter分頁(yè)類(lèi)pagination使用方法示例”,方便廣大網(wǎng)友查閱!

本文實(shí)例講述了CodeIgniter分頁(yè)類(lèi)pagination使用方法。分享給大家供大家參考,具體如下:

controller控制器(application/controller/page.php文件):

public function index()

{

    $this->load->model ( 'home_model' , '' , TRUE);

    $config= array();

    $config['per_page'] = $this->per_page; //每頁(yè)顯示的數(shù)據(jù)數(shù)

    $current_page    = intval($this->input->get_post('per_page',true)); //獲取當(dāng)前分頁(yè)頁(yè)碼數(shù)

    //page還原

    if(0 == $current_page)

    {

      $current_page = 1;

    }

    $offset = ($current_page - 1 ) * $config['per_page']; //設(shè)置偏移量 限定 數(shù)據(jù)查詢(xún) 起始位置(從 $offset 條開(kāi)始)

    $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;//首頁(yè)

    $config['prev_link']     = $this->prev_link;//上一頁(yè)

    $config['next_link']     = $this->next_link;//下一頁(yè)

    $config['last_link']     = $this->last_link;//尾頁(yè)

    $config['total_rows']     = $result['total'];//總條數(shù)

    $config['num_links'] = 3;//頁(yè)碼連接數(shù)

    $config['use_page_numbers']  = TRUE;

    $config['page_query_string'] = TRUE;

    $this->load->library('pagination');//加載ci pagination類(lèi)

    $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(),

    );

}

希望本文所述對(duì)大家基于CodeIgniter框架的PHP程序設(shè)計(jì)有所幫助。

更多信息請(qǐng)查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機(jī)網(wǎng)站地址:CodeIgniter分頁(yè)類(lèi)pagination使用方法示例
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢(xún)回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門(mén)公布的正式信息和咨詢(xún)?yōu)闇?zhǔn)!

2025國(guó)考·省考課程試聽(tīng)報(bào)名

  • 報(bào)班類(lèi)型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢(xún) | 簡(jiǎn)要咨詢(xún)須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專(zhuān)用圖標(biāo)
聯(lián)系電話(huà):0871-65099533/13759567129 獲取招聘考試信息及咨詢(xún)關(guān)注公眾號(hào):hfpxwx
咨詢(xún)QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專(zhuān)用圖標(biāo)