My search box is included in the header. I want so that when I type any word for a search it grabs results from my database and goes to the search view page with results. My header is also included on different controllers.
here is my controller
public function index()
{
if($this->input->post('submit'))
{
if($this->input->post('search') == '')
{
redirect('search');
}
$keyword = $this->input->post('search');
$data['rows'] = $this->search_model->search($keyword);
}
$this->load->view('header');
$this->load->view('search',$data);
$this->load->view('footer');
}
here is my model
function search($keyword)
{
$this->db->like('title', $keyword);
$this->db->or_like('type', $keyword);
$query = $this->db->get('mytable');
return $query->result();
}
here is my view
<form class="navbar-form" role="search" action="<?php echo base_url();?>search" method="post">
<div class="input-group cust-input">
<input type="text" class="form-control" placeholder="Search" name="search">
<div class="input-group-btn ">
<button class="btn btn-default cust-searchbtn" type="submit" name="submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>
But when I search for something it redirects to my search page with empty results. I want to do search in the header and send results to my search page where I show the results on that page.