The benefit of using any web application framework is that you don’t have to worry about the common tasks like input handling, form validation and the like, as the framework already provides wrappers for those features. Thus, it allows you to concentrate on the business logic of the application rather than reinventing the wheel over and over again.

Today, we’re going to explore an important library in the CodeIgniter framework—the pagination library.

CodeIgniter provides a very simple, but flexible pagination library that is simple to theme, works with the model, and capable of supporting multiple paginators on a single page.

Let me highlight the topics that we’re going to cover in the course of this article:

  • Demonstration of basic paging
  • Explore the customization options
  • Pagination configuration
Steps to implement pagination

Below are the simple steps to create pagination in Codeigniter and MySQL.

Step 1 : Create Table In MySQL.

CREATE TABLE test.user ( id INT ( 6 ) UNSIGNED AUTO_INCREMENT PRIMARY KEY , name VARCHAR ( 30 ) NOT NULL , email VARCHAR ( 50 ), mobno bigint ( 10 ) ).

Step 2 : Insert Some Data Into Table.

INSERT INTO user ( id , name , email , mobno ) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user ( id , name , email , mobno ) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user ( id , name , email , mobno ) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user ( id , name , email , mobno ) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user ( id , name , email , mobno ) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user ( id , name , email , mobno ) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user ( id , name , email , mobno ) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user ( id , name , email , mobno ) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user ( id , name , email , mobno ) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user ( id , name , email , mobno ) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user ( id , name , email , mobno ) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user ( id , name , email , mobno ) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user ( id , name , email , mobno ) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user ( id , name , email , mobno ) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user ( id , name , email , mobno ) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user ( id , name , email , mobno ) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );INSERT INTO user ( id , name , email , mobno ) VALUES (NULL , ‘gfgfd’ , ‘test@gmail.com’ , ‘65464877’ );

Step 3 : Update application/config/database.php.

$db**[** ‘default’] = array**(** ‘dsn’ => ‘’ , ‘hostname’ => ‘localhost’ , ‘username’ => ‘root’ , ‘password’ => ‘’ , ‘database’ => ‘dbname’ , ‘dbdriver’ => ‘mysqli’ , ‘dbprefix’ => ‘’ , ‘pconnect’ => FALSE , ‘db_debug’ => ( ENVIRONMENT !== ‘production’) , ‘cache_on’ => FALSE , ‘cachedir’ => ‘’ , ‘char_set’ => ‘utf8’ , ‘dbcollat’ => ‘utf8_general_ci’ , ‘swap_pre’ => ‘’ , ‘encrypt’ => FALSE , ‘compress’ => FALSE , ‘stricton’ => FALSE , ‘failover’ => array**()** , ‘save_queries’ => TRUE**)** ;

Step 3 : Create a new model User_Model in application/models.

< ?php class User_Model extends CI_Model**{** private $table = ‘user’ ; public function getCount**()** { return $this -> db -> count_all**(** $this -> table**)** ; } public function getUsers**($limit** , $start)** { $this -> db -> limit**($limit** , $start)** ; $query = $this -> db -> get**(** $this -> table**)** ; return $query -> result**()** ; }} ?>

#codeigniter #mysql

Codeigniter MySQL Pagination Example
1.65 GEEK