Paging dengan Code Igniter (Indonesia Version)

1 2 3 > Last ›

Nama Alamat Kota
Rio Saja jl. pilar mas raya kav. a-d jakarta
andy jl. diponegoro bandung
Elen Medan Medan

Jumlah : 3

ya itu kira2 tampilannya …. DEMO nya bisa lihat di blogs saya ini juga .. klik disini ..

catatan :
1. Framework yang digunakan Code Igniter (MVC)
2. MVC yang digunakan hanya View dan Controller (gak mau repot pake Model) hehehehe ..
3. Catatan penting yang perlu dilihat adalah konfigurasi : route (agar uri segment nya dapat berjalan dengan baik)
4. config.php — $config[‘base_url’] = “http://localhost/programming/coba/”;
5. Routes.php
———————————————————————————————————————
$route[‘default_controller’] = “welcome”;
$route[‘scaffolding_trigger’] = “”;
$route[‘welcome/:num’] = “welcome”; //kuncinya di routing ini …

catatan :

1. Framework yang digunakan Code Igniter (MVC)

2. MVC yang digunakan hanya View dan Controller (gak mau repot pake Model) hehehehe ..

3. config.php — $config[‘base_url’] = “http://localhost/programming/coba/”;

4.

Controller: Welcome.PHP (Cukup satu File Saja)

———————————————————————————————————————

<?php

class Welcome extends Controller {

function Welcome()

{

parent::Controller();

$this->load->database();

}

function index()

{

//load default paging library

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

//sesuaikan konfigurasi berikut dengan system anda..

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

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

$config[‘uri_segment’] = 2;

//query ini hanya utk ambil total row datanya saja

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

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

$jumlah=$query->num_rows();

$config[‘total_rows’] = $jumlah;

$this->pagination->initialize($config);

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

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

$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 ————–

5. 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”;

?>

<br><br>

————————————–  selesai ——————————————————-

tambahan :

ini table dan row data mysql yg saya gunakan …. selamat mencoba …..

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’);

3 thoughts on “Paging dengan Code Igniter (Indonesia Version)

Leave a Reply

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