这是代码工作良好,但只适用于一列搜索,即user
在下面的代码,但需要搜索多个列,如password
, email
public function index()
{
$this->input->post('search'); //this is drag from view table *name=search*
$search=$this->input->post('search');
$data['user']=$this->usermodel->searchUser($search);
$this->load->view('user',$data);
}
public function searchUser($search=null)
{
$this->db->select("*");
$this->db->from("tbl_user");
$this->db->where("user",$search); //user is one column of table *tbl_user*
$query=$this->db->get();
if($query->num_rows()>0)
{
$result=$query->result_array();
return $result;
} else {
return false;
}
}
你可以在像这样的地方使用多个
$this->db->where('email',$email);
$this->db->where('password',$password);
您可以使用array
并传递array
。Associative array
方法:
$array = array('user' => $user, 'email' => $email, 'password' => $password);
$this->db->where($array);
// Produces: WHERE user = 'Joe' AND email = 'joe@example.com' AND password = 'password'
请查看CI查询生成器类了解详细信息