我想在我的搜索表单中创建 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");
}
}