Codeigniter 单击CI分页链接会产生错误的查询

Codeigniter 单击CI分页链接会产生错误的查询,codeigniter,pagination,Codeigniter,Pagination,我目前在使用CodeIgniter点击我网站的分页链接时遇到问题。搜索功能运行良好,但是,当我单击任何分页链接时,它似乎一次又一次地进行筛选 例如: if( $this->input->post(null) ){ #if the form is submitted $saleType = $this->input->post('sale_type'); $propType = $this->input->post('prop_t

我目前在使用CodeIgniter点击我网站的分页链接时遇到问题。搜索功能运行良好,但是,当我单击任何分页链接时,它似乎一次又一次地进行筛选

例如:

if( $this->input->post(null) ){     #if the form is submitted
    $saleType   = $this->input->post('sale_type');
    $propType   = $this->input->post('prop_type');
    $city       = $this->input->post('city');
    $district   = $this->input->post('district');
    $commune    = $this->input->post('commune');    
}else{
    $saleType   = $this->uri->segment(3);
    $propType   = $this->uri->segment(5);
    $city       = $this->uri->segment(7);
    $district   = $this->uri->segment(9);
    $commune    = $this->uri->segment(11);
}


$search['base_url']     = base_url() . 'page_search/sale_type/'.$saleType.'/prop_type/'.$propType.'/city/'.$city.'/district/'.$district.'/commune/'.$commune.'/page/';
$search['uri_segment']  = 13;
我选择“租金”作为搜索的选项:

然后点击搜索,我得到27个结果。之后,我单击底部的“2”分页按钮:

我又得到了73个结果等等

我的控制器:

$this->load->library('pagination');
$search['base_url'] = base_url() . 'page_search/';
$search['per_page'] = 5;
$search['num_links'] = 5;
$search['num_tag_open'] = '<li>';
$search['num_tag_close'] = '</li>';
$search['first_link'] = 'First';
$search['first_tag_open'] = '<li class="first">';
$search['first_tag_close'] = '</li>';
$search['last_tag_open'] = '<li class="last">';
$search['last_tag_close'] = '</li>';
$search['next_tag_open'] = '<li>';
$search['next_tag_close'] = '</li>';
$search['prev_tag_open'] = '<li>';
$search['prev_tag_close'] = '</li>';
$search['last_link'] = 'Last';
$search['next_link'] = '&raquo;';
$search['prev_link'] = '&laquo;';
$search['full_tag_open'] = '<div class="pagination pagination-centered"><ul>';
$search['full_tag_close'] = '</ul></div>';
$search['cur_tag_open'] = '<li class="active"><a href="#">';
$search['cur_tag_close'] = '</a></li>';
$search['total_rows'] = $this->db->get_where( 'listing', $where )->num_rows();
$search['uri_segment'] = 2;
$config['use_page_numbers'] = TRUE;

$this->pagination->initialize( $search );
$this->db->order_by("id", "desc");
$this->db->where( $where );
$data['results'] = $this->db->get( 'listing', $search['per_page'], $this->uri->segment(2);
$data['rows'] = $this->db->get_where( 'listing', $where )->num_rows();

$data['content'] = 'website/page-search';
$this->load->view('template/website/theme', $data);

这是指向live站点的链接

您正在发布搜索表单并制作
$where
语句,这很酷,但在第2页,您的
$where
语句是否正常工作?我想这是你需要注意的地方。在第二页打印生成的查询,如下所示:

$this->db->last_query();
您需要以某种方式将这些
搜索参数
传递到下一页,以正确生成
$where
条件。例如:

if( $this->input->post(null) ){     #if the form is submitted
    $saleType   = $this->input->post('sale_type');
    $propType   = $this->input->post('prop_type');
    $city       = $this->input->post('city');
    $district   = $this->input->post('district');
    $commune    = $this->input->post('commune');    
}else{
    $saleType   = $this->uri->segment(3);
    $propType   = $this->uri->segment(5);
    $city       = $this->uri->segment(7);
    $district   = $this->uri->segment(9);
    $commune    = $this->uri->segment(11);
}


$search['base_url']     = base_url() . 'page_search/sale_type/'.$saleType.'/prop_type/'.$propType.'/city/'.$city.'/district/'.$district.'/commune/'.$commune.'/page/';
$search['uri_segment']  = 13;

啊,我明白了。我已打印视图中的最后一个查询结果。它显示,当单击分页按钮时,查询将重新运行。当用户没有选择某些选项时,我仍然有一个问题。你认为还有比这更灵活的吗?对每个搜索字段使用默认值,比如所有类型、所有社区等等。。