当我进行搜索时,所有记录都会显示,并且分页链接也会显示在视图页面中。
此外,当我在视图页面中选择分页链接时,显示的空白记录不在数据库中。
以下是控制器
public function users() {
$this->load->library('pagination');
$data1['showdata']=$this->searchmodelresult->login($look,$age, $age_to,$age_from,$se_ct,$subsect,$coun_try,$sta_te, $ci_ty,$qualification);
$count=$data1['showdata'];
$totalrows=$count['count'];
$config = array();
$config["base_url"] = base_url() . "search/users";
$config["total_rows"] = $totalrows;
$config["per_page"] = 2;
$config["uri_segment"] = 3;
$this->pagination->initialize($config);
$this->load->view('templatepages/searchresult',$data1,$result);
}
以下是视图页面。
<?php echo $this->pagination->create_links();?>
答案 0 :(得分:1)
if($this->uri->segment(3)){
$page = ($this->uri->segment(3)) ;
}
else{
$page = 1;
}
$data["results"] = $this->pagination_model->fetch_data($config["per_page"], $page);
您可以参考以下链接:https://www.formget.com/pagination-in-codeigniter/
希望这个答案能帮到你。
答案 1 :(得分:0)
试试这个 - 测试并使用我的
您的URI细分将为2 -
$config['uri_segment'] = 2;
在控制器中
$count = $this->searchmodelresult->get_count($look,$age, $age_to,$age_from,$se_ct,$subsect,$coun_try,$sta_te, $ci_ty,$qualification);
//product pagination
$config['base_url'] = base_url() . 'search/users';
$config['total_rows'] = $count;
$config['per_page'] = 2;
$config['uri_segment'] = 2;
$limit = $config['per_page'];
$this->pagination->initialize($config);
$page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
$data['links'] = $this->pagination->create_links();
$data['preview'] = $this->searchmodelresult->login($look,$age, $age_to,$age_from,$se_ct,$subsect,$coun_try,$sta_te, $ci_ty,$qualification, $limit,$page); # $limit and $page is added.
$this->load->view('templatepages/searchresult',$data)
在模型中
public function login($look,$age, $age_to,$age_from,$se_ct,$subsect,$coun_try,$sta_te, $ci_ty,$qualification, $limit,$page)
{
$query = $this->db->query("SELECT * .... LIMIT $page, $limit");
$result = $query->result_array();
return $result;
}
public function get_count($look,$age, $age_to,$age_from,$se_ct,$subsect,$coun_try,$sta_te, $ci_ty,$qualification)
{
$query = $this->db->query("SELECT * .... ");
$result = $query->result_array();
$count = count($result);
return $count;
}