結合クエリを使用してデータを取得しました。結合されたテーブルから一部のデータが削除された場合、ページネーションに問題が発生します
コントローラーコード
function index($msg='',$offset = 0)
{
$data = array('title'=>'Towns','message'=>'', 'link_add'=>site_url('manage/town/add'), 'edit_link'=>site_url('manage/town/edit'), 'tbl'=>'towns' );
$uri_segment = 4;
$offset = $this->uri->segment($uri_segment);
// load data
$value=('towns.Id,towns.Name as TownName,city.Name as CityName,city.Status,towns.Status,towns.TaxAmount');
$data['list_records'] = $this->admin_model->get_joinlist($data['tbl'],$value,'city','city.Id = towns.cityId','left outer','towns.Id','asc',array('towns.Status !='=>'Delete','city.Status'=>'Enable'),$this->limit, $offset)->result();
if($msg=='m')$data['message'] = 'New Town has been added successfully!';
// generate pagination
$this->load->library('pagination');
$config['base_url'] = site_url('manage/town/index/');
$this->total = $this->admin_model->**count_all**($data['tbl'],array('Status !='=>'Delete'));
$config['total_rows'] = $this->total;
$config['per_page'] = $this->limit;
$config['uri_segment'] = $uri_segment;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['j'] = 0 + $offset;
$data['total_rows']= $this->total;
// load view
$this->load->view('manage/includes/header', $data);
$this->load->view('manage/town', $data);
$this->load->view('manage/includes/footer');
}
<?php
class Admin_model extends CI_Model {
//listing with join
public function get_joinlist($table,$value,$table2,$condi,$join_type,$order_by,$order,$where,$limit, $offset)
{
$this->db->select($value);
$this->db->join($table2,$condi,$join_type);
$this->db->order_by($order_by,$order);
$this->db->where($where);
return $query= $this->db->get($table, $limit, $offset);
}
//For pagination
function count_all($table,$where)
{
return $this->db->where($where)
->count_all_results($table);
}
function num_rows($table)
{
return $this->db->affected_rows($table);
}