对不起,主人......我是codeigniter的nubie(2个月)
我想问一下codeigniter 2.1.0中的分页,其中来自模型的查询结果
这是我的模型:
这是我的控制器
最后一个是我的 config.php
$config['limit_data'] = '10';
需要你的建议大师:)
谢谢你的时间。
更新:对于文本: http: //palinghoki.com/codeigniter-pagination.txt
对不起,主人......我是codeigniter的nubie(2个月)
我想问一下codeigniter 2.1.0中的分页,其中来自模型的查询结果
这是我的模型:
这是我的控制器
最后一个是我的 config.php
$config['limit_data'] = '10';
需要你的建议大师:)
谢谢你的时间。
更新:对于文本: http: //palinghoki.com/codeigniter-pagination.txt
你需要两个函数。首先,计算用户拥有的文件总数,其次是明智地获得结果分页。您在这里做错的是您在一个查询中获取所有记录而没有限制。
按照my previous
这个答案。
编辑:
function ListCabangKaryawan()
{
return $q = $this->db->query("select b.branch_code,b.branch_name,count(bk.status_karyawan) as jml_karyawan,
SUM(B.ANGGOTA+B.DANRU+B.WADANRU+B.SECWAN+B.PKD+B.DANKI+B.ADMIN+B.RESEPSIONIS+B.LIDIK+B.ASS_CHIEF+B.CHIEF+B.KORDINATOR) AS jml_komposisi
from branch b left join biodata_karyawan bk
on b.branch_code=bk.branch_code
and bk.status_karyawan='Aktif'
where b.status='a'
group by b.branch_code order by b.branch_code")->num_rows();
}
function ListCabangKaryawanByLimit($limit, $offset = 0){
if( !$offset ){
$offset = 0;
}
return $q = $this->db->query("select b.branch_code,b.branch_name,count(bk.status_karyawan) as jml_karyawan,
SUM(B.ANGGOTA+B.DANRU+B.WADANRU+B.SECWAN+B.PKD+B.DANKI+B.ADMIN+B.RESEPSIONIS+B.LIDIK+B.ASS_CHIEF+B.CHIEF+B.KORDINATOR) AS jml_komposisi
from branch b left join biodata_karyawan bk
on b.branch_code=bk.branch_code
and bk.status_karyawan='Aktif'
where b.status='a'
group by b.branch_code order by b.branch_code limit {$offset}, {$limit}")->result_array();
}
function index()
{
$cek = $this->session->userdata('logged_in');
$cek2 = $this->session->userdata('level');
if(!empty($cek))
{
$d['judul'] = 'ERP - '.$this->config->item('nama_perusahaan');
$d['nama_perusahaan'] = $this->config->item('nama_perusahaan');
$d['alamat_perusahaan'] = $this->config->item('alamat_perusahaan');
$d['lisensi'] = $this->config->item('lisensi_app');
$bc['menu'] = $this->load->view('app/menu', '', true);
$bc['bio'] = $this->load->view('app/bio', $bc, true);
$limit = 20; //say 20 items to show per page.
$offset = $this->uri->segment(3); //this is the offset to use in query
$config['base_url'] = base_url() . 'karyawan_front/index/';
$config['total_rows'] = $this->app_model->ListCabangKaryawan();
$config['per_page'] = $limit;
$config['uri_segment'] = 3;
$config['first_link'] = 'Awal';
$config['last_link'] = 'Akhir';
$config['next_link'] = 'Selanjutnya';
$config['prev_link'] = 'Sebelumnya';
$this->pagination->initialize($config);
$bc["paginator"] =$this->pagination->create_links();
//tampilan data
$bc['dt_cabang'] = $this->app_model->ListCabangKaryawanByLimit($limit, $offset);
$q_total = $this->app_model->TotalCabang();
if($q_total->num_rows()>0)
{
foreach($q_total->result() as $w)
{
$bc['total'] = $w->total;
}
}
else
{
$bc['total'] = '0';
}
$this->load->view('global/bg_top',$d);
$this->load->view('karyawan_front/bg_home',$bc);
$this->load->view('global/bg_footer',$d);
}
else
{
$st = $this->session->userdata('status');
if($st=='a')
{
header('location:'.base_url().'app');
}
else
{
header('location:'.base_url().'front');
}
}
}
编辑 2
if(isset( $dt_cabang ) && is_array( $dt_cabang ) && count( $dt_cabang ) > 0 )
{
foreach($dt_cabang as $db)
{
?>
<tr>
<td><?php echo $no; ?></td>
<td><?php echo $db['branch_name']; ?></td>
<td><?php echo $db['branch_code']; ?></td>
<td><?php echo $db['jml_karyawan']; ?></td>
<td><?php echo $db['jml_komposisi']; ?></td>
<td><?php
$jml_karyawan = $db['jml_karyawan'];
$jml_komposisi = $db['jml_komposisi'];
$kekurangan_personil = $jml_karyawan - $jml_komposisi;
if($kekurangan_personil < 0)
{
echo '<font color="red">' . $kekurangan_personil . '</font>';
}
else if($kekurangan_personil == 0)
{
echo '<font color="blue">COMPLITE</font>';
}
else
{
echo '<font color="green">OVER BUDGET :' . $kekurangan_personil . '</font>';
}
}
}