2014-07-19 4 views
1

페이지 매김에 문제가 있습니다. 내 페이지 매김이 제대로 작동하지 않습니다. 제 데이터 계산에 문제가 있다고 생각합니다.페이지 매김 codeigniter 결과를 반복하십시오.

그것은 내 테이블 (fc_kategori)

idkategory| namakategory 

내 컨트롤러

function kategori($offset=NULL,$x=NULL) 
{ 
    $cek = $this->bymodel->cekaman(); 
    if($cek!=null) 
    {  

    $tbl='fc_kategori'; 
    $x = $this->input->post('cari');// it's for searching data() 
    $field='namakategori'; 
    $data['include'] = 'admin/list_category'; 
    $config['base_url'] = base_url().'admin/kategori/.'; 
    $config['uri_segment'] = 3; 
    $config['total_rows'] = $this->bymodel->hitungdata($tbl,$field,$x); 
    $config['per_page'] = 5; 
    $config['use_page_numbers'] = TRUE; 
    $config['full_tag_open'] = '<div id="pagination">'; 
    $config['full_tag_close'] = '</div>'; 
    $offset = ($this->uri->segment($config['uri_segment'])) ? $this->uri->segment($config['uri_segment']) : 0; 
    $this->pagination->initialize($config); 
    $data['halaman'] = $this->pagination->create_links(); 
    $data['kategori'] = $this->bymodel->tampildata2($config['per_page'], $offset,$tbl,$x,$field); 
      $this->load->view('admin/template/page',$data); 
    }else{ 
    $this->load->view('login'); 
} 

그리고 그것은 내 모델

function hitungdata($tbl,$field,$x) 
{ 
    $this->db->like($field, $x); 
    $this->db->from($tbl); 
    return $this->db->count_all_results();  
} 

public function tampildata2($num, $offset,$tbl,$x,$field) 
{ 
    $this->db->like($field, $x); 
    $this->db->where('flag',1); 
    $data = $this->db->get($tbl, $num, $offset); 
    return $data->result(); 
} 

페이지 매김이 아니라 제대로 작동합니다. 사전

업데이트

에서

My first page 
- pemrograman 
- PHP 
- CSS 
- HTML 5 
- Codeigniter 

My second page 
- CSS //showing twice 
- HTML 5 //showing twice 
- Codeigniter //showing twice 
- CSS 3 

덕분에 내가

$config['use_page_numbers'] = TRUE; 

모든 것이 제대로 작동 삭제 한 후. 하지만 내 URL이 함수에 오는 변수 오프셋 $ 실제로 데이터베이스에 전달할 필요가 오프셋 아닌 설정과 페이지 번호이며이

first page => kategori/ 
second page => kategori/5 
+0

당신이 여기에 전체 URL을 게시 할 수 있습니까? – mrsrinivas

답변

0

처럼 보인다. 나는 (예) $ 중 PAGE_NUMBER이 변수 이름을 변경 제안하고, 따라서 그 오프셋 실제 $을 계산하는 것 :

function kategori($page_number=NULL,$x=NULL) 
{ 
    $per_page = 5; // also reference this later when setting $config['per_page'] so it's not repeated 
    $offset = 0; // default 
    if (!is_null($page_number)) 
    { 
    $offset = ($page_number - 1) * $per_page; 
    } 

    //... the rest of the function as before 
} 
관련 문제