0

我想在我的搜索表单中创建 codeigniter 分页,当我点击提交时,它成功显示查询搜索,但是当我点击数字页面链接或下一页时,它显示消息“未定义变量 rec”和“致命错误:调用非对象上的成员函数 num_rows()”,我确定查询已传递给变量 $rec。

当我更改页面时,我在这里看到了问题,变量返回 null,所以变量 $rec 没有从“post”中获取值。

我的问题:我如何保留'post'的值,以便在我更改页面时查询将获得变量值?

这是我的控制器:

public function search(){

$kat=$this->input->post('kategori');
$prov=$this->input->post('prov');
$kot=$this->input->post('kota');


if($kat=='' && $prov!='' && $kot!=''){
$rec=$this->db->query("select * from showall where id_prov='$prov' and id_kota='$kot' ");
}
else if($kot=='' && $kat!='' && $prov!=''){
$rec=$this->db->query("select * from showall where id_kat='$kat' and id_prov='$prov' ");
}
else if($kat=='' && $kot=='' && $prov!=''){
$rec=$this->db->query("select * from showall where id_prov='$prov' ");
}
else if($kat!='' && $prov=='' && $kot==''){
$rec=$this->db->query("select * from showall where id_kat='$kat' ");
}
else if($kat!='' && $prov!='' && $kot!=''){
$rec=$this->db->query("select * from showall where id_kat='$kat' and id_prov='$prov' and id_kota='$kot' ");
}

$dat=$rec;
$data['count']=$dat->num_rows();
  if($data['count'] >0){
  $data['db']=$rec;
$config['total_rows'] = $data['db']->num_rows(); 

$config['base_url'] = base_url().'index.php/lowongan/cari';

$config['per_page'] = 1;    
$config['uri_segment'] = 3;
$this->pagination->initialize($config);
$data['paging'] = $this->pagination->create_links();
if($kat=='' && $prov!='' && $kot!=''){
$d = $this->db->get_where('showall',array('id_prov'=>$prov,'id_kota'=>$kot) ,$config['per_page'], $this->uri->segment(3));
}
else if($kot=='' && $kat!='' && $prov!=''){
$d= $this->db->get_where('showall',array('id_kat'=>$kat,'id_prov'=>$prov) ,$config['per_page'], $this->uri->segment(3));
}
else if($kat=='' && $kot=='' && $prov!=''){
$d = $this->db->get_where('showall',array('id_prov'=>$prov) ,$config['per_page'], $this->uri->segment(3));
}
 if($kat!='' && $prov=='' && $kot==''){
$d = $this->db->get_where('showall',array('id_kat'=>$kat) ,$config['per_page'], $this->uri->segment(3));
}
else if($kat!='' && $prov!='' && $kot!=''){
$d = $this->db->get_where('showall',array('id_kat'=>$kat,'id_prov'=>$prov,'id_kota'=>$kot) ,$config['per_page'], $this->uri->segment(3));
}

$data['record']=$d;
$data1['kat']=$this->query->kategoriAll();
$data1['prov']=$this->query->showProv();
$data['q1']=$this->query->lokasi();
$data['q2']=$this->query->perusahaan();
$data['q3']=$this->query->kategori();

$this->load->view("user/head");
$this->load->view("user/bar",$data1);   
$this->load->view( 'user/hal_cari',$data);
$this->load->view("user/footer");
}
else{
$data1['kat']=$this->query->kategoriAll();
$data1['prov']=$this->query->showProv();
$data['q1']=$this->query->lokasi();
$data['q2']=$this->query->perusahaan();
$data['q3']=$this->query->kategori();

$this->load->view("user/head");
$this->load->view("user/bar",$data1);   
$this->load->view( 'user/kosong',$data);
$this->load->view("user/footer");
}
}
4

1 回答 1

0

您需要使用 assoc_to_uri() 将条件数组保留在 URL 中。我正在做如下。

    $this->load->model('classified_model','classified');
    $ClassifiedList = $this->classified->searchPage($condition,'classified_view',$perPage,$page*$perPage);
    $uriString = $this->uri->assoc_to_uri($condition);
    $config['uri_segment'] = count($condition) * 2 + 4;
    $base_url = site_url('classified/search/' . $uriString . '/page/');
    $base_url = preg_replace("/\.[a-z]*$/","", $base_url);
    $config['base_url'] = $base_url;
    $config['per_page'] = 1;

要再次从 uri 中获取 $condition,请使用

   $condition = $this->uri->uri_to_assoc();
于 2013-08-21T06:44:01.563 回答