Home  • Framework • CodeIgniter

Pagination in CodeIgniter from multiple table

getting started codeigniter department table +--------------+----------------+ | DepartmentID | DepartmentName | +--------------+----------------+ | 1 | Admin | | 2 | Accounts | | 3 | Software | | 4 | Support | +--------------+----------------+ emp table +----+--------------+--------------+--------+---------+ | ID | EmployeeName | DepartmentID | Salary | address | +----+--------------+--------------+--------+---------+ | 1 | Tom | 2 | 600 | NULL | | 2 | Jerry | 1 | 800 | NULL | | 3 | Doraemon | 3 | 700 | NULL | | 4 | Maxwell | 3 | 500 | NULL | | 5 | Jones | 1 | 650 | NULL | +----+--------------+--------------+--------+---------+
<?php
class Pagination extends Controller {

	function Pagination()
	{
		parent::Controller();	
		
	}
	
	function index(){
          $this->page();
	}
	
	function page($page=0){
		$this->load->library('pagination');
		
		
		$query=$this->db->query("select count(*) 'rows' from emp e,department d where d.departmentid=e.departmentid");
		
		$row=$query->row_array();
		$parpage=2;
		
        $config=array();
		$config['base_url'] = 'http://localhost/codeigniter/index.php/pagination/page/';
		$config['uri_segment'] = 3;
		$config['num_links'] = 3;
		$config['total_rows'] =$row["rows"];
		$config['per_page'] =$parpage; 
        
		$this->pagination->initialize($config); 

		echo $this->pagination->create_links();	
		
		
		$limit=$page.",".$parpage;
		
	
	    $query=$this->db->query("select e.employeename,d.departmentname,e.salary  from emp e,department d where d.departmentid=e.departmentid limit $limit");
		
		echo "<br/>";
		foreach($query->result_array() as $rows){
			echo $rows["employeename"]." | ".$rows["departmentname"]."<br/>";
		}
	    
		
	}
	
}

Comments 0


Copyright © 2024. Powered by Intellect Software Ltd