Last active
August 29, 2015 14:23
-
-
Save SunDi3yansyah/340df64c29c43785ad37 to your computer and use it in GitHub Desktop.
Pagination CodeIgniter with JOIN by SunDi3yansyah
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// MODEL | |
function function_pagination($table_1, $num, $offset, $table_2, $join, $order) | |
{ | |
$this->db->select('*'); | |
$this->db->join($table_2,$join); | |
$this->db->order_by($order); | |
$data = $this->db->get($table_1, $num, $offset); | |
return $data->result(); | |
} | |
?> | |
<?php | |
// CONTROLLER | |
function function($id=NULL) | |
{ | |
$total = $this->db->get('table_1'); | |
$config = array( | |
'base_url' => base_url('class/function'), | |
'total_rows' => $total->num_rows(), | |
'per_page' => 10 | |
); | |
$this->pagination->initialize($config); | |
$data = array( | |
'pages' => $this->pagination->create_links(), | |
'query' => $this->smansaka_crud->function_pagination('table_1', $config['per_page'], $id, 'table_2','table_1.tb1_field_1=table_2.tb2_field_1','tb1_field_1 DESC') | |
); | |
$this->load->view('file', $data); | |
} | |
?> | |
<!-- VIEW --> | |
<?php foreach ($query as $field): ?> | |
<!-- code --> | |
<?php endforeach; ?> | |
<?php echo $pages; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment