Php 下拉过滤器不工作
我在Stackoverflow上看到了一个过滤器示例,我试图在我的codeigniter上实现它,但当我单击go按钮时,它不会过滤它。它返回我总是Php 下拉过滤器不工作,php,codeigniter,Php,Codeigniter,我在Stackoverflow上看到了一个过滤器示例,我试图在我的codeigniter上实现它,但当我单击go按钮时,它不会过滤它。它返回我总是找不到用户这有什么问题 控制器 public function filter($page=0,$offset=5,$search=''){ $user = $this->session->userdata('user_id'); $position = $this->session->userd
找不到用户
这有什么问题
控制器
public function filter($page=0,$offset=5,$search=''){
$user = $this->session->userdata('user_id');
$position = $this->session->userdata('user_position');
if($position =='admin'){
$search = $this->input->post('search');
$row = $this->m_user->getAllFilterUsers($offset,$page,$search);
$data['usersTable'] = $row->result();
$data['pagination'] = $this->m_user->getUsersFilterPages($search);
$data['offset'] = $offset;
$data['page'] = $page;
$data['search'] = $search;
$data['title'] = 'Manage Users';
$this->load->view('vadminuserfilter',$data);
}
else{
$this->session->set_flashdata('error','Page Not Found.');
redirect('cuser/displayClientPage');
return;
}
}
模型
看法
筛选依据:
只需检查型号的getAllFilterUsers功能。$offset的值为5,$count的值为0。
但是你用
this->db->where('user_position','client');
$this->db->where('user_status','active');
$this->db->order_by('user_id', 'desc');
$UsersQuery = $this->db->get('tb_user',$offset,$count);
那意味着
Select * from tb_user where user_position = 'client' and 'user_status' = 'active' order by user_id desc limit 5,0
此查询始终返回空集
你的问题应该是
Select * from tb_user where user_position = 'client' and 'user_status' = 'active' order by user_id desc limit 0,5
因此,您的代码片段应该是
this->db->where('user_position','client');
$this->db->where('user_status','active');
$this->db->order_by('user_id', 'desc');
$UsersQuery = $this->db->get('tb_user',$count,$offset);
最后,函数是
public function getAllFilterUsers($offset,$count,$search){
if($search!=''){
$this->db->where('user_position','client');
$this->db->where('user_status',$search);
}
this->db->where('user_position','client');
$this->db->where('user_status','active');
$this->db->order_by('user_id', 'desc');
$UsersQuery = $this->db->get('tb_user',$count,$offset);
if($UsersQuery->num_rows>0){
return $UsersQuery;
}
else{
$this->session->set_flashdata('message','No User Found');
redirect('cuser/filter','refresh');
}
}
这就是问题的标题。不,我们不会调试你的代码。请先找出错误的原因。您是否在任何地方进行错误检查?我建议您检查您的方法是否接收到必要的参数。正如@hakra所说,我们不调试代码,我们需要错误来找到解决方案
this->db->where('user_position','client');
$this->db->where('user_status','active');
$this->db->order_by('user_id', 'desc');
$UsersQuery = $this->db->get('tb_user',$count,$offset);
public function getAllFilterUsers($offset,$count,$search){
if($search!=''){
$this->db->where('user_position','client');
$this->db->where('user_status',$search);
}
this->db->where('user_position','client');
$this->db->where('user_status','active');
$this->db->order_by('user_id', 'desc');
$UsersQuery = $this->db->get('tb_user',$count,$offset);
if($UsersQuery->num_rows>0){
return $UsersQuery;
}
else{
$this->session->set_flashdata('message','No User Found');
redirect('cuser/filter','refresh');
}
}