开发者

CodeIgniter Pagination

I after some help with codeIgniter pagination (fixign a bug).. I can see the number of records and the pagination link in the view but when click on the next link, it does not show the next/previous 10 records. Can someone please help me with this?

I have the following code in my controller

function customerlist_pagination()
{
  $search = $this->input->post('search');
  $data['title'] = "Customer Clist";
  $data['heading'] = "List of customers";
  $data['result'] = $this->customers_model->getAllcustomers_pagination($search_para, FALSE, "limit_rows");
  $data['num_recs'] = $this->customers_model->getAllcustomers_pagination($search_para, FALSE, "num");
  $config['base_url'] = base_url().'index.php/customer/customerlist_pagination/';
  $config['total_rows'] = $data['num_recs'];
  $config['pe开发者_如何学Gor_page'] = 10;
  $config['uri_segment'] = 3;
  $config['next_link'] = 'Next >';
  $config['prev_link'] = '< Previous ';
  $this->pagination->initialize($config);
  $this->load->view('customer_view_table',$data);
}

In the model, I have the following code:

function getAllSeizures_pagination($search_para, $archive_search = FALSE, $result_type)
{   
    $search_para = $search_para."%";
    $selected_fields = "customer.firstName
    customer.lastName, customer.address,
    customer.city, customer.postcode";
    $from = "customer";     
    $where = "customer.deleted=0 ";
    if ($archive_search == TRUE) {
      $where .= "AND customer.archived= 1 ";
    }else{
       $where .= "AND customer.archived= 0 ";
    }
    $where .= "AND (customer.firstName LIKE '$search_para' OR customer.postcode LIKE '$search_para' OR customer.city LIKE '$search_para')";
    $query =  $this->db->select($selected_fields, false)
                    ->from($from)
                    ->where($where)    
                    ->order_by('customer.idcustomer', 'desc');

   if($result_type == "limit_rows") 
   {
      $query = $this->db->limit(10, 0)
                        ->get();
      $query =  $query->result();
   }

    if($result_type == "num") {
         $query = $this->db->get();
    $query = $query->num_rows();
   }

   return $query;
}

Thanks alot

Regards Prats


The pagination class passes the offset to you in the uri_segment specified. Since you set it to 3, you should capture that info in the first variable of your controller method, like so:

function customerlist_pagination( $offset )
{
}

Then, when you call your $this->customers_model->getAllcustomers_pagination(), you have to pass it the $offset, so that later on in your code, where you limit your results:

$query = $this->db->limit(10, 0)->get();

you should instead use this $offset to limit your results:

$query = $this->db->limit(10, $offset)->get();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜