Home > Backend Development > PHP Tutorial > CodeIgniter paging class pagination usage example, codeigniter example_PHP tutorial

CodeIgniter paging class pagination usage example, codeigniter example_PHP tutorial

WBOY
Release: 2016-07-12 08:55:04
Original
882 people have browsed it

CodeIgniter paging class pagination usage example, codeigniter example

This article describes how to use CodeIgniter paging class pagination. Share it with everyone for your reference, the details are as follows:

controller (application/controller/page.php file):

public function index()
{
    $this->load->model ( 'home_model' , '' , TRUE);
    $config= array();
    $config['per_page'] = $this->per_page; //每页显示的数据数
    $current_page    = intval($this->input->get_post('per_page',true)); //获取当前分页页码数
    //page还原
    if(0 == $current_page)
    {
      $current_page = 1;
    }
    $offset = ($current_page - 1 ) * $config['per_page']; //设置偏移量 限定 数据查询 起始位置(从 $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'];//总条数
    $config['num_links'] = 3;//页码连接数
    $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 );
}

Copy after login

model model (application/model/home_model.php file):

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(),
    );
}

Copy after login

Readers who are interested in more CodeIgniter related content can check out the special topics of this site: "codeigniter introductory tutorial", "CI (CodeIgniter) framework advanced tutorial", "php date and time usage summary", "php object-oriented program" Design introductory tutorial", "php string (string) usage summary", "php mysql database operation introductory tutorial" and "php common database operation skills summary"

I hope this article will be helpful to everyone’s PHP program design based on the CodeIgniter framework.

Articles you may be interested in:

  • CodeIgniter’s method of sending html emails using smtp service
  • Codeigniter’s method of sending emails and printing debugging information
  • Codeigniter Methods of sending emails
  • Codeigniter implements sending emails with attachments
  • CodeIgniter-assisted third-party class library third_party usage analysis
  • Detailed explanation of CodeIgniter extended core class instances
  • CI (Codeigniter) Setting enhanced configuration class instance
  • PHP implements the shopping cart class that imitates CodeIgniter
  • Codeigniter dom class usage instance
  • Codeigniter shopping cart class cannot be added Chinese solution
  • CodeIgniter’s method of sending emails based on the Email class

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1117097.htmlTechArticleCodeIgniter paging class pagination usage example, codeigniter example This article describes the use of CodeIgniter paging class pagination. Share it with everyone for your reference, the details are as follows:...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template