id传递中的codeigniter分页错误

时间:2014-11-20 09:42:36

标签: php codeigniter pagination

 $category_id=$_GET['category_id'];
  $data['adsd']=$this->mymodel->select_ads_by_category($category_id);   
  $config["base_url"]=site_url('main/category_ads_display?category_id='.$category_id.'');

  $config["total_rows"]=count($data['adsd']);
  $limit=$config["per_page"]=1;
  $config["uri_segment"]=3;
        $config["use_page_numbers"]=TRUE;
  $this->pagination->initialize($config);
  if($this->uri->segment(3))
   $page=($this->uri->segment(3)-1)*$limit;
  else
  $page=0;

朋友您好我已粘贴上面的代码,一切正常,但是当我点击分页链接时,网址就像这样= localhost / blabla / main / category_ads_display?category_id = 5/2(不工作)< / p>

但我需要将url设为as = localhost / blabla / main / category_ads_display / 2?category_id = 5(工作) 请帮帮我

1 个答案:

答案 0 :(得分:0)

试试这种方式

 $category_id=$this->uri->segment(3);
 $data['adsd']=$this->mymodel->select_ads_by_category($category_id);
 config["base_url"]=site_url('main/category_ads_display/'.$category_id);

 $config["total_rows"]=count($data['adsd']);
 $limit=$config["per_page"]=1;
 $config["uri_segment"]=4;
 $config["use_page_numbers"]=TRUE;
 $this->pagination->initialize($config);
 if($this->uri->segment(4))
  $page=($this->uri->segment(3)-1)*$limit;
 else
 $page=0;

现在,您的新链接将如此localhost/blabla/main/category_ads_display/5/2用于第2页,而5将是您的类别ID