codeigniter pagination数字未正确显示

时间:2012-09-05 11:59:27

标签: codeigniter pagination

Codeigniter分页数字在结果页面中未正确显示。

Plz帮帮我。

/ 控制器页面代码 /

  function search_all()
  {
    $this->load->view(‘prd’); 
  $config = array();
  $config[‘base_url’] =  base_url().’/product_search/search_all’;
  $config[“total_rows”] = $this->search_product_model->record_count();
    $config[“per_page”] = 8;
    $config[“uri_segment”] = 3;

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

    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    $data[“results”] = $this->search_product_model->
    get_search($config[“per_page”], $page);
    $data[“links”] = $this->pagination->create_links();

    //$this->load->view(“example1”, $data);
  $this->load->view(‘asd’, $data);
  }

3 个答案:

答案 0 :(得分:0)

我认为这个

存在问题
  $config[“total_rows”] = $this->search_product_model->record_count();

为此你没有传递搜索键,它会计算它包含的所有数据。如果你根据搜索键得到记录数,那就没关系。就像这个

  $config[“total_rows”] = $this->search_product_model->record_count('//search parameters');

并在您的模型中:

Public function record_count($search_params)
{
   $this->db->where('product',$search_params);
   return $this->db->count_all(“products”);
}

您可以根据需要修改,例如将“color”,“type”传递给您的record_count()函数,并根据该函数建议您获取“count_all”。我希望它能为您服务

答案 1 :(得分:0)

试试这个

 function search_all()
 {               
   $config[‘base_url’] =  base_url(’product_search/search_all’);
   $config[“total_rows”] = $this->search_product_model->record_count();//2 in your case
   $config[“per_page”] = 8;
   $config[“uri_segment”] = 3;

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

$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data[“results”] = $this->search_product_model->
get_search($config[“per_page”], $page);
$data[“links”] = $this->pagination->create_links();

//$this->load->view(“example1”, $data);
$this->load->view(‘asd’, $data);
}

并在你的模特:

 public function get_search($limit, $page)
{
 //Add this...???
  $this->db->limit($limit, $page);  //or try $this->db->limit($page,$limit)

}

答案 2 :(得分:0)

将record_count()函数中的搜索键作为参数//你有2个na。??

然后在placeof search_params中放入提供给record_count()的相同键