Tutorial on Creating a Search Pagination Session in Codeigniter

In this tutorial we will learn how to create a search system for data tables that have pagination with the help of sessions in Codeigniter, of course you will ask what sessions in pagination are for, it will be easier to understand after you compare ordinary pagination with pagination sessions, enough discussion now we will start .

codeigniter search pagination session
Photo Illustration via cnblogs.com

First create a database with the name of the exercise, table and input some data, the following is the sql:

— Database: practice

— Structure of the pagination . table

CREATE TABLE IF NOT EXISTS pagination (
nim bigint(20) NOT NULL,
name varchar(50) NOT NULL,
major varchar(30) NOT NULL,
address text NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=111999030 DEFAULT CHARSET=latin1;

— Data dumping for pagination . table

INSERT INTO pagination (nim, name, department, address) VALUES
(111999014, ‘Rahmayanti’, ‘PGSD’, ‘Kp. Mekarsari RT.15/03 No.33’),
(111999021, ‘Muhammad Yusuf Hamdani’, ‘Informatics Engineering’, ‘Jln. Cipaku Haji RT.02/07 No.15’),
(111999023, ‘Putri Andini’, ‘Information System’, ‘Kp. Mekarsari RT/RW 22/55 No.34’),
(111999025, ‘Anggra Triawan Skom’, ‘S2 Infirmatics Engineering’, ‘Kp. Buntar RT.02 / RW.09 Kel. Ciawi Kec. Bogor Selatan’),
(111999027, ‘Alisya Rahmadani’, ‘PGBK’, ‘Pakuan Hill Housing, Monte Carlo, Ciawi Bogor Selatan’),
(111999029, ‘Muhammad Afnan’, ‘Law’, ‘Pakuan Hill Housing, Monte Carlo, Ciawi Bogor Selatan’);

— Indexes for dumped tables

— Indexes for table pagination

ALTER TABLE pagination
ADD PRIMARY KEY(nim);

— AUTO_INCREMENT for dumped tables

— AUTO_INCREMENT for table pagination

ALTER TABLE pagination
MODIFY nim bigint(20) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=111999030;
SQL Database
The database structure in phpmyadmin will look like below

ps1

The filled table will look like below

ps2

In this tutorial we need a .htaccess file (this file has no name, only has an .htaccess extension) to remove index.php in the url, please create a new file then save the file in the pagination_session_ci / project folder.

RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
.htaccess
To make it easier for friends, you can download .htaccess

Open the autoload.php file, which is located in application/config/autoload.php, then find and modify the helpers and libraries section like this:

$autoload[‘libraries’] = array(‘database’, ‘session’, ‘pagination’);
$autoload[‘helper’] = array(‘url’, ‘file’, ‘form’);
application/config/autoload.php
Open the config.php file, which is located in application/config/config.php, then find and modify it like this:

$config[‘base_url’] = ‘http://localhost/pagination_session_ci/’;

$config[‘encryption_key’] = ‘TWD’;
application/config/config.php
Open the database.php file, which is located in application/config/database.php, then find and modify it like this:

$active_group = ‘default’;
$active_record = TRUE;

application/config/database.php
Then open the welcome.php file, controllers/welcome.php and edit it as below: