php - Codeigniter Pagination Using Query in Model -
i want make pagination using codeigniter doesn't work succesfully. in model use this
function show_kegiatan($offset,$limit) { $query= $this->db->query("select kegiatan . * , lk . * , fakultas.* , count( kegiatan_review.reviews ) 'komentar', fakultas.* kegiatan inner join lk on lk.id_lk = kegiatan.id_lk inner join fakultas on fakultas.id_fakultas = lk.id_fakultas left outer join kegiatan_review on kegiatan.id_kegiatan = kegiatan_review.id_kegiatan group kegiatan.id_kegiatan order kegiatan.tahun_periode desc limit $offset",$limit); if ($query->num_rows() > 0) { return $query->result(); } }
in controller
public function kegiatan($offset=0) { $data['user']=$this->m_login->get_user($this->session->userdata('sesi_admin')); $jml = $this->db->get('kegiatan'); $config['base_url'] = base_url().'admin/kegiatan'; $config['total_rows'] = $jml->num_rows(); $config['per_page'] = 3; $config['uri_segment'] = 3; $config['full_tag_open'] = "<ul class='pagination pagination-sm' style='position:relative; top:-25px;'>"; $config['full_tag_close'] ="</ul>"; $config['num_tag_open'] = '<li>'; $config['num_tag_close'] = '</li>'; $config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>"; $config['cur_tag_close'] = "<span class='sr-only'></span></a></li>"; $config['next_tag_open'] = "<li>"; $config['next_tagl_close'] = "</li>"; $config['prev_tag_open'] = "<li>"; $config['prev_tagl_close'] = "</li>"; $config['first_tag_open'] = "<li>"; $config['first_tagl_close'] = "</li>"; $config['last_tag_open'] = "<li>"; $config['last_tagl_close'] = "</li>"; $this->pagination->initialize($config); $data['halaman'] = $this->pagination->create_links(); $data['offset'] = $offset; $data['kegiatan'] = $this->m_admin->show_kegiatan($config['per_page'], $offset); $this->load->templateadmin('in/admin_kegiatan',$data); }
in output, offset work , data doesn't work succesfully. whats wrong model?
you can use $this->uri->segment(3)
replace $offset
please try sample, rest must change fit need...
in model :
function show_kegiatan($perpage, $uri) { $uri = ($uri == null || $uri==''?0:$uri); $this->db->select('kegiatan.kolommu1,kegiatan.kolommu2,lk.kolommu1,lk.kolommu2')->from('kegiatan')->join('lk','lk.id_lk = kegiatan.id_lk')->order_by('kegiatan.id_kegiatan','desc')->limit($perpage,$uri); $hasil = $this->db->get()->result_array(); return (sizeof($hasil) > 0?$hasil:null); }
in controller :
function kegiatan(){ $jml = $this->db->get('kegiatan')->num_rows(); $config['full_tag_open'] = "<ul class='pagination pagination-sm' style='position:relative; top:-25px;'>"; $config['full_tag_close'] ="</ul>"; $config['num_tag_open'] = '<li>'; $config['num_tag_close'] = '</li>'; $config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>"; $config['cur_tag_close'] = "<span class='sr-only'></span></a></li>"; $config['next_tag_open'] = "<li>"; $config['next_tagl_close'] = "</li>"; $config['prev_tag_open'] = "<li>"; $config['prev_tagl_close'] = "</li>"; $config['first_tag_open'] = "<li>"; $config['first_tagl_close'] = "</li>"; $config['last_tag_open'] = "<li>"; $config['last_tagl_close'] = "</li>"; $config['base_url'] = site_url('admin/kegiatan'); $config['total_rows'] = $jml; $config['per_page'] = 3; $config['uri_segment'] = 3; $config['first_link'] = 'awal'; $config['last_link'] = 'akhir'; $config['next_link'] = 'selanjutnya'; $config['prev_link'] = 'sebelumnya'; $this->pagination->initialize($config); $data['kegiatan'] = $this->m_admin->show_kegiatan($config['per_page'], $this->uri->segment(3)); $data['halaman'] = $this->pagination->create_links(); $this->load->view('layout/admin/v_dashboard',$data); $this->load->templateadmin('in/admin_kegiatan',$data); }
Comments
Post a Comment