2012-09-19 2 views
0

나는 성공적으로 내가 함께 일하고있는 응용 프로그램의 일부 페이지에 페이지 매김을 만든에서 작동하지 않습니다,하지만 난이 일에 그것을 할 수 없습니다 데이터베이스, 페이지가 표시되면 5 개가 아닌 7 개의 레코드가 모두 표시됩니다.매김은 CodeIgniter의

물론, 페이징 링크는 표시되지 않습니다. 여기

내 컨트롤러 코드 :

public function displayAllFaqCategories() 
    { 

     //initializing & configuring paging 

     $currentUser = $this->isLoggedIn(); 
     $this->load->model('faqCategoriesModel'); 
     $this->db->order_by('sorder'); 
     $limit = 5; 
     $offset = 3; 

     $offset = $this->uri->segment(3); 
     $this->db->limit(5, $offset); 

     $data['faq_categories'] = $this->faqCategoriesModel->selectCategoriesAndParents(); 
     $totalresults = $this->db->get('faq_categories')->num_rows(); 

     //initializing & configuring paging 
     $this->load->library('pagination'); 
     $config['base_url'] = site_url('/backOfficeUsers/faqcategories'); 
     $config['total_rows'] = $totalresults; 
     $config['per_page'] = 5; 
     $config['uri_segment'] = 3; 


     $this->pagination->initialize($config); 

     $errorMessage = ''; 
     $data['main_content'] = 'faq/faqcategories'; 
     $data['title'] = 'FAQ Categories'; 

     $this->load->vars($data,$errorMessage); 
     $this->load->vars($currentUser); 
     $this->load->view('backOffice/template'); 

    } // end of function displayAllFaqCategories 

그리고 여기 내 모델 기능 코드 : 나는 다음과 같은 코드를 가지고있는 레코드 테이블의 노호 뷰에서

public function selectCategoriesAndParents($selectWhat = array()) 
    {  
     $data = array(); 
     $query = $this->db->query("SELECT fq . * , COALESCE(fqp.$this->parent_name, '0') AS parentname 
            FROM $this->table_name AS fq 
            LEFT OUTER JOIN $this->table_name AS fqp ON fqp.catid = fq.parentid"); 
     if($query->num_rows() > 0) 
     { 
      foreach($query->result_array() as $row) 
       { 
        $data[] = $row; 
       } 
      }   
     $query->free_result(); 
     return $data; 
    } // end of function selectCategoriesAndParents  

:

<?php echo $this->pagination->create_links();?> 

도움이 될 것입니다.

감사합니다, 당신은 다른 두 가지를 혼합 한이

$offset = $this->uri->segment(3) ? $this->uri->segment(3) : 0; 

답변

1

같은 조란

+0

당신은 manavo를 흔든다. 고마워. – Zoran

0

편집 함께 나는 생각한다. 부분적으로 ActiveRecord 클래스의 CI를 사용하지만 직접 쿼리를 실행합니다.

간단한 변화는 다음과 같습니다

// get all the rows 
    $data['faq_categories'] = $this->faqCategoriesModel->selectCategoriesAndParents(); 
    // figure out the count of all of them 
    $totalresults = count($data['faq_categories']); 
    // only take some of the rows of the array, instead of keeping all of them and then showing all 7 of your records 
    $data['faq_categories'] = array_splice($data['faq_categories'], $offset, $limit); 

희망을 수정해야한다고!

더 원래의 문제가 무엇인지 설명하기 위해, 나는 당신이 실행할 때 생각 :

$totalresults = $this->db->get('faq_categories')->num_rows(); 

이 계정에 이전 줄 $this->db->limit(5, $offset); 소요, 그래서 5 개 행을 반환합니다. 그런 다음 매 페이지 라이브러리에 페이지 당 5 개만 표시한다고 말하면 라이브러리는 실제로 모든 결과를 보여주고 있다고 생각하므로 페이지 매김 링크가 필요 없습니다!

+0

다음과 같이 코드를 변경합니다. // $ offset = $ this-> uri-> segment (3); $ offset = $ this-> uri-> segment (3)? $ this-> uri-> segment (3) : 0; 결과는 동일하게 유지되며 모든 7 개의 레코드가 표시되고 페이지 매김 링크가 없습니다 ... – Zoran

+0

아니오 .. ?? wat는 $ Totalpages ..의 값입니다. – Gautam3164