This is the code work fine but only for one column search which is user
in below code, but need to search more than one column like password
, email
controller
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);
}
model
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;
}
}
You can use multiple where like this
$this->db->where('email',$email);
$this->db->where('password',$password);
You can use an array
and pass the array
. Associative array
method:
$array = array('user' => $user, 'email' => $email, 'password' => $password);
$this->db->where($array);
// Produces: WHERE user = 'Joe' AND email = 'joe@example.com' AND password = 'password'
Please check CI Query Builder Class for details