Create Database table
CREATE TABLE `country` ( `id` smallint(5) UNSIGNED NOT NULL, `printable_name` varchar(255) NOT NULL, `CountryAbbrev` varchar(10) DEFAULT NULL, `CurrencyAbbr` varchar(4) DEFAULT NULL, `CurrencyRate` float DEFAULT NULL, `CurrencyCode` varchar(3) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Codeigniter Base Url Configuration
$config['base_url'] = "http://localhost/codeIgniter3_1_10_pagination/";
Pagination Controller (pagenation.php) application\controllers\pagenation.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <?php defined( 'BASEPATH' ) OR exit ( 'No direct script access allowed' ); class Pagenation extends CI_Controller { public function __construct() { parent:: __construct(); $this ->load->helper( "url" ); $this ->load->model( "Countries" ); $this ->load->library( "pagination" ); } public function pagenum() { $config = array (); $config [ "base_url" ] = base_url() . "pagenation/pagenum" ; $config [ "total_rows" ] = $this ->Countries->record_count(); $config [ "per_page" ] = 20; $config [ "uri_segment" ] = 3; $choice = $config [ "total_rows" ] / $config [ "per_page" ]; $config [ "num_links" ] = round ( $choice ); $this ->pagination->initialize( $config ); $page = ( $this ->uri->segment(3))? $this ->uri->segment(3) : 0; $data [ "results" ] = $this ->Countries->fetch_countries( $config [ "per_page" ], $page ); $data [ "links" ] = $this ->pagination->create_links(); $this ->load->view( "expagenation" , $data ); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <?php class Countries extends CI_Model { public function __construct() { parent::__construct(); } public function record_count() { return $this ->db->count_all( "country" ); } public function fetch_countries( $limit , $start ) { $this ->db->limit( $limit , $start ); $query = $this ->db->get( "country" ); if ( $query ->num_rows() > 0) { foreach ( $query ->result() as $row ) { $data [] = $row ; } return $data ; } return false; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | <!DOCTYPE html> <html lang= "en" > <head> <meta charset= "utf-8" > <meta http-equiv= "X-UA-Compatible" content= "IE=edge" > <meta name= "viewport" content= "width=device-width, initial-scale=1" > <title>Codeigniter 3.1.10 Dev - Pagination</title> <link href= "https://netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel= "stylesheet" id= "bootstrap-css" > </head> <body> <div class = "container" > <h1>Countries</h1> <div id= "body" > <?php foreach ( $results as $data ) { echo $data ->printable_name . " - " . $data ->CountryAbbrev . "<br>" ; } ?> <p> <div class = "pagination" > <?php echo $links ; ?> </div> </p> </div> <p class = "footer" >Page rendered in <strong>{elapsed_time}</strong> seconds</p> </div> <style> .pagination a { padding: .5rem .75rem; margin-left: -1px; line-height: 1.25; color: #007bff; background-color: #fff; border: 1px solid #dee2e6; } .pagination strong{ z-index: 2; color: #fff; cursor: default ; background-color: #428bca; border-color: #428bca; padding: 6px 16px; margin-left: -1px; color: #fff; text-decoration: none; } </style> </body> </html> |
http://localhost/codeIgniter3_1_10_pagination/pagenation/pagenum
Download http://bit.ly/2Ey5xIu