<form method="post" action="<?php echo base_url(); ?>users/find">
<input type="text" placeholder="Search for user..." name="search">
<input type="submit" value="Search">
</form>
public function find() {
$search = $this->input->post('search');
$this->load->model('HomeModel');
$data['user'] = $this->HomeModel->test($search);
$this->load->view('found', $data);
}
public function test($search) {
// This is an absolute match
$q = $this->db
->where('id',$search)
->or_where('name',$search)
->or_where('email',$search)
->or_where('salary',$search)
->or_where('address',$search)
->get('users');
// https://www.codeigniter.com/user_guide/database/query_builder.html#looking-for-similar-data
// If relative matches are what you are seeking.
$q = $this->db
->like('id',$search)
->or_like('name',$search)
->or_like('email',$search)
->or_like('salary',$search)
->or_like('address',$search)
->get('users');
// If you only want to see the user ones
// Add the following above.
$this->db->group_by('id');
// This will only give you the first match
return $q->row_array();
// This will give you every match
$results = array();
foreach ($q->result_array() as $row)
{
$results[] = $row;
}
return $results;
}