SIMPLE PAGING WITH CODEIGNITER FRAME WORK (English Version)

PAGING WITH CODEIGNITER FRAME WORK BY : Rio Uniwaly
——————————————————-
Demo for this paging you can see it here : http://rio.uniwaly.com/programming/coba/
notes :
1. Framework used : Code Igniter (MVC)
2. I’m using MVC with View and Controller only. i’m not used Model.
4. This is my config files configuration : config.php — $config[‘base_url’] = “http://localhost/programming/coba/”;
5. Controller: Welcome.PHP (One Controller Only)
—-
<?php
/* paging controller sample by Rio Uniwaly
http://www.rio.uniwaly.com
http://www.godblesshosting.com
*/
class Welcome extends Controller {
function Welcome()
{
parent::Controller();
$this->load->database();
}
function index()
{
//load default paging library
$this->load->library(‘pagination’);
//configure this according to your systems!
$config[‘base_url’] = ‘http://localhost/programming/coba/index.php/welcome/’;
$config[‘per_page’] = ‘3’;
$config[‘uri_segment’] = 2;
//this query only for getting total rows!
$this->db->select(‘nama, alamat, kota’); /* means select name,alamat,kota from member tables */
$query=$this->db->get(‘member’);
$jumlah=$query->num_rows(); /* i put the total of the rows in jumlah variables */
$config[‘total_rows’] = $jumlah; // save the rows for config files…
$this->pagination->initialize($config);  // initialize configuration files …
echo $this->pagination->create_links();
$data[‘num’]=$config[‘per_page’];// this important also … $num means the limit. you should know limit and offset in mysql
//$data[‘offset’]=$config[‘uri_segment’];
$data[‘offset’]=$this->uri->segment(2);
if (!$data[‘offset’])
{
$data[‘offset’]=0;
}
$data[‘num’] = $config[‘per_page’];
$this->load->view(‘rio’,$data);
}
}
/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */
————————————————————————————————————- end of controller ————–
6. VIEWS : RIO.PHP
—————–
<table border=1>
<tr>
<td>Nama
<td>Alamat
<td>Kota
<?
$this->db->select(‘nama, alamat, kota’);
$query=$this->db->get(‘member’,$num,$offset);
$jumlah = count($query->result());
foreach ($query->result() as $row)
{
echo “<tr><td>”.$row->nama;
echo “<td>”.$row->alamat;
echo “<td>”.$row->kota;
}
?>
</td></tr></table>
<?
echo “Jumlah : $jumlah”; // this is the total rows that will shown up..
?>
<br><br>
<br><br>
————————————————- END OF VIEWS —————————————
—- this is the database i used ..  :  start copy ————————————–
— phpMyAdmin SQL Dump
— version 2.11.4
— http://www.phpmyadmin.net
— Host: localhost
— Generation Time: Sep 30, 2009 at 12:56 AM
— Server version: 5.0.51
— PHP Version: 5.2.5
SET SQL_MODE=”NO_AUTO_VALUE_ON_ZERO”;
— Database: `rio_ci`
— —————————————————————————————————————————-
— Table structure for table `member`
CREATE TABLE IF NOT EXISTS `member` (
`id` int(11) NOT NULL auto_increment,
`nama` varchar(50) NOT NULL,
`alamat` varchar(255) NOT NULL,
`kota` varchar(50) NOT NULL,
`keterangan` text NOT NULL,
PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;
— Dumping data for table `member`
INSERT INTO `member` (`id`, `nama`, `alamat`, `kota`, `keterangan`) VALUES
(1, ‘Rio Saja’, ‘jl. pilar mas raya kav. a-d’, ‘jakarta’, ‘ini keterangannya saja’),
(2, ‘andy’, ‘jl. diponegoro’, ‘bandung’, ‘ini usernya cumi’),
(3, ‘Elen’, ‘Medan’, ‘Medan’, ‘ini testing untuk elen’),
(4, ‘Tiano’, ‘Semanan’, ‘Cengkareng’, ‘datanya Tiano’),
(5, ‘icul’, ‘blok m’, ‘jaksel’, ‘jaksel data icul’),
(6, ‘lanny’, ‘kayumanis’, ‘jaktim’, ‘data lanny’),
(7, ‘george’, ‘bogor’, ‘bogor’, ‘data george’),
(8, ‘adolf’, ‘bekasi’, ‘bekasi’, ‘data adolf’),
(9, ‘gill’, ‘jatinegara’, ‘jaktim’, ‘data gill’),
(10, ‘steve’, ‘percetakan negara ‘, ‘jaktim’, ‘data steve’);
———————————————————————— end copy database ————————————–

ciSIMPLE PAGING WITH CODEIGNITER FRAME WORK

Demo for this paging you can see it here : http://rio.uniwaly.com/programming/coba/

notes :

1. Framework used : Code Igniter (MVC)

2. I’m using MVC with View and Controller only. i’m not using Model.

4. This is my config files  : config.php — $config[‘base_url’] = “http://localhost/programming/coba/”;

5. Controller: Welcome.PHP (One Controller Only)

<?php

/* paging controller sample by Rio Uniwaly

http://www.rio.uniwaly.com

http://www.godblesshosting.com

*/

class Welcome extends Controller {

function Welcome()

{

parent::Controller();

$this->load->database();

}

 

function index()

{

 

//load default paging library

$this->load->library(‘pagination’);

 

//configure this according to your systems!

$config[‘base_url’] = ‘http://localhost/programming/coba/index.php/welcome/’;

$config[‘per_page’] = ‘3’;

$config[‘uri_segment’] = 2;

 

//this query only for getting total rows!

$this->db->select(‘nama, alamat, kota’); /* means select name,alamat,kota from member tables */

$query=$this->db->get(‘member’);

$jumlah=$query->num_rows(); /* i put the total of the rows in jumlah variables */

$config[‘total_rows’] = $jumlah; // save the rows for config files…

$this->pagination->initialize($config);  // initialize configuration files …

echo $this->pagination->create_links();

$data[‘num’]=$config[‘per_page’];// this important also … $num means the limit. you should know limit and offset in mysql

//$data[‘offset’]=$config[‘uri_segment’];

$data[‘offset’]=$this->uri->segment(2);

if (!$data[‘offset’])

{

$data[‘offset’]=0;

}

$data[‘num’] = $config[‘per_page’];

$this->load->view(‘rio’,$data);

}

}

/* End of file welcome.php */

/* Location: ./system/application/controllers/welcome.php */

——————————— end of controller ————–

6. VIEWS : RIO.PHP

<table border=1>

<tr>

<td>Nama

<td>Alamat

<td>Kota

<?

$this->db->select(‘nama, alamat, kota’);

$query=$this->db->get(‘member’,$num,$offset);

$jumlah = count($query->result());

foreach ($query->result() as $row)

{

echo “<tr><td>”.$row->nama;

echo “<td>”.$row->alamat;

echo “<td>”.$row->kota;

}

?>

</td></tr></table>

<?

echo “Jumlah : $jumlah”; // this is the total rows that will shown up..

?>

<br><br>

<br><br>

——————– END OF VIEWS ———–

—- this is the database i used ..  :  start copy ———–

— phpMyAdmin SQL Dump

— version 2.11.4

— http://www.phpmyadmin.net

— Host: localhost

— Generation Time: Sep 30, 2009 at 12:56 AM

— Server version: 5.0.51

— PHP Version: 5.2.5

SET SQL_MODE=”NO_AUTO_VALUE_ON_ZERO”;

— Database: `rio_ci`

— Table structure for table `member`

CREATE TABLE IF NOT EXISTS `member` (

`id` int(11) NOT NULL auto_increment,

`nama` varchar(50) NOT NULL,

`alamat` varchar(255) NOT NULL,

`kota` varchar(50) NOT NULL,

`keterangan` text NOT NULL,

PRIMARY KEY  (`id`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;

— Dumping data for table `member`

INSERT INTO `member` (`id`, `nama`, `alamat`, `kota`, `keterangan`) VALUES

(1, ‘Rio Saja’, ‘jl. pilar mas raya kav. a-d’, ‘jakarta’, ‘ini keterangannya saja’),

(2, ‘andy’, ‘jl. diponegoro’, ‘bandung’, ‘ini usernya cumi’),

(3, ‘Elen’, ‘Medan’, ‘Medan’, ‘ini testing untuk elen’),

(4, ‘Tiano’, ‘Semanan’, ‘Cengkareng’, ‘datanya Tiano’),

(5, ‘icul’, ‘blok m’, ‘jaksel’, ‘jaksel data icul’),

(6, ‘lanny’, ‘kayumanis’, ‘jaktim’, ‘data lanny’),

(7, ‘george’, ‘bogor’, ‘bogor’, ‘data george’),

(8, ‘adolf’, ‘bekasi’, ‘bekasi’, ‘data adolf’),

(9, ‘gill’, ‘jatinegara’, ‘jaktim’, ‘data gill’),

(10, ‘steve’, ‘percetakan negara ‘, ‘jaktim’, ‘data steve’);

———– end copy database ——-

Leave a Reply

Your email address will not be published. Required fields are marked *