CodeIgniter Laravel PHP Example Javascript jQuery MORE Videos New

Pagination in Codeigniter Mysqli With Example and Demo

Create a new model Students_model in application/models.


class Students_model extends CI_Model {
	protected $table = 'students_data';
	public function __construct() {
	public function get_count() {
        return $this->db->count_all($this->table);
	public function get_students($limit, $start) {
        $this->db->limit($limit, $start);
        $query = $this->db->get($this->table);
		return $query->result();

Create a new file Students.php in application/controllers directory


defined('BASEPATH') OR exit('No direct script access allowed');
class Students extends CI_Controller {
	public function __construct() {
        parent:: __construct();
	public function index() {
        $config = array();
        $config["base_url"] = base_url() . "students";
        $config["total_rows"] = $this->students_model->get_count();
        $config["per_page"] = 10;
        $config["uri_segment"] = 2;
		$page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
		$data["links"] = $this->pagination->create_links();
		$data['students'] = $this->students_model->get_authors($config["per_page"], $page);
		$this->load->view('students/index', $data);

Create a new file index.php in application/views/students/index.php


<!DOCTYPE html>
        <title>CodeIgniter Pagination</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <div class="container">
            <h3>CodeIgniter Database Pagination</h3>
            <div class="column">
                            <th>First Name</th>
                            <th>Last Name</th>
                        <?php foreach ($students as $student): ?>
                                <td><?= $student->id; ?></td>
                                <td><?= $student->first_name; ?></td>
                                <td><?= $student->last_name; ?></td>
                                <td><?= $student->email; ?></td>
                                <td><?= $student->phone ;?></td>
                        <?php endforeach; ?>
                <p><?php echo $links; ?></p>