2012-07-14 73 views
0

我在顯示分頁時遇到了一些問題。即使只有一個查詢,分頁也會出現。我知道這是我在缺少的$ Pagesquery上的sql語句。Codeigniter分頁配置(SQL語句)

這是我的控制器

//This will only display local packages 
    public function displayLocalPackages($page=0,$offset=6,$search=''){ 

     $search = $this->input->post('search');  
     $row = $this->m_tour->getAllLocalTours($offset,$page,$search); 
     $data['usersTable'] = $row->result(); 
     $data['pagination'] = $this->m_tour->getLocTourPages(); 
     $data['offset'] = $offset; 
     $data['page'] = $page; 
     $data['search'] = $search; 
     $data['title'] = 'Local Packages'; 
     $this->load->view('vdisplaylocaltours',$data); 

    } 

這是我的模型功能

//will get the number of local pages 

    public function getLocTourPages(){ 
    $Pagesquery = $this->db->get('tb_package'); 
      $config['base_url'] = site_url('ctour/displayLocalPackages'); 
    $config['total_rows']= $Pagesquery->num_rows(); 
      $config['per_page'] = 6; 
      $config['first_link'] = 'First'; 
      $config['prev_link'] = 'Previous'; 
      $config['next_link'] = 'Next'; 
      $config['last_link'] = 'Last'; 
      $this->pagination->initialize($config); 
    return $this->pagination->create_links(); 

    } 

public function getAllLocalTours($offset,$count,$search){ 

     #This will only occur if $search is NOT empty 
     if ($search!=''){ 
       $this->db->where("(cat_id LIKE '%1%' AND pack_name LIKE '%$search%')"); 
        $this->db->where('pack_status','available'); 
     } 

     #cat_id corresponds with the local packages 
      $this->db->where('cat_id',1); 
      $this->db->where('pack_status','available'); 
      $this->db->order_by('pack_name', 'desc'); 
      $this->db->order_by('pack_id', 'desc'); 

     #Query on the table package 
      $LocalQuery = $this->db->get('tb_package',$offset,$count); 

      if($LocalQuery->num_rows > 0){ 
       return $LocalQuery; 
      } 
      else{ 
      return FALSE; 
     }   
    } 

回答

0

總行數應該是

$config['total_rows']= $Pagesquery->num_rows()/6; //per page is given as 6 in your code 
+0

你好,Nish,謝謝你的回答。分頁消失,但當數據超過6個時,它不顯示另一個,並且沒有「下一個」鏈接。 – 2012-07-14 17:42:00

0

嘿嘿一邊看着我的代碼意識到我ju st需要在'getLocTourPages'函數中放入相同的sql查詢:P

$ this-> db-> where('cat_id',1); $ this-> db-> where('pack_status','available');