CodeIgniter How to Pagination
CodeIgniter is a powerful PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications. If you’re a developer who lives in the real world of shared hosting accounts and clients with deadlines, and if you’re tired of ponderously large and thoroughly undocumented frameworks.
CodeIgniter’s Pagination class is very easy to use, and it is 100% customizable, either dynamically or via stored preferences.
If you are not familiar with the term “pagination”, it refers to links that allows you to navigate from page to page, like this:
function shownews()
{
if($this->userlib->logged_in())
//checking for security purposes
{
$this->load->library('pagination');
$per_page = 10;
// How many pages you want to show in each page
$total = $this->db->get('posts', $per_page, $this->uri->segment(3));
//Here is the most important part actually.
Basically $total variable determined which
rows you are going to show in the page
$config['base_url'] = base_url().'/index.php/admin/shownews';
$config['total_rows'] = $this->db->count_all('posts'); // Count total rows in the query
$config['per_page'] = $per_page;
$config['num_links'] = 6;
$this->pagination->initialize($config);
$data['posts'] = $total;
$this->load->view('admin_shownews', $data);
} else {
$this->load->view('admin_logineed');
}
}
After getting done with this configuration part of pagination class all you have to do is just initialize it like you are doing it in most of programming languages.
Tweet
Thanks for dropping by! Feel free to join the discussion by leaving comments, and stay updated by subscribing to the

Recent Comments