Welcome Guest, Not a member yet? Register   Sign In
PHP search with spaces
#1

[eluser]Kraig[/eluser]
Currently I have a a search that searches through uploaded file names. The search works great if you only have one word, but when I start putting spaces it doesn't do what I want it to. I'm thinking in order to search for each word I will need to explode the string and search the array. Any other good ideas out there?
Here's my model:
Code:
public function search($key)
{
  $query = $this->db->query('SELECT * FROM upload WHERE name LIKE "%'.$key.'%"');
  $this->num_rows = $query->num_rows();
  $val = $query->result_array();
  
  return $query;
}

Controller:
Code:
function index()
{
  $name= $_POST['keywords'];
  $val = "";
  $search = $this->upload_model->search($name);
  
  if(strlen($name) < 4) {
   $this->error = "Minimum search length is 3.";
  }else {
   if($search->num_rows() > 0) {
    $val = $search->result_array();
   }else {
    $this->error = "Sorry, no matches were found.";
   }
  }
  
  $data['search'] = $val;
  $data['error'] = $this->error;
  
  $data['main_content'] = 'search';
  $this->load->view('includes/template2', $data);

}


Messages In This Thread
PHP search with spaces - by El Forum - 08-22-2012, 07:30 PM
PHP search with spaces - by El Forum - 08-22-2012, 10:01 PM
PHP search with spaces - by El Forum - 08-22-2012, 10:14 PM
PHP search with spaces - by El Forum - 08-22-2012, 11:28 PM
PHP search with spaces - by El Forum - 08-23-2012, 02:51 PM
PHP search with spaces - by El Forum - 08-23-2012, 03:06 PM
PHP search with spaces - by El Forum - 08-24-2012, 06:16 AM
PHP search with spaces - by El Forum - 08-24-2012, 06:25 AM
PHP search with spaces - by El Forum - 08-24-2012, 11:28 AM
PHP search with spaces - by El Forum - 08-24-2012, 11:50 AM
PHP search with spaces - by El Forum - 08-24-2012, 05:02 PM
PHP search with spaces - by El Forum - 08-24-2012, 07:14 PM
PHP search with spaces - by El Forum - 08-24-2012, 07:35 PM
PHP search with spaces - by El Forum - 08-25-2012, 12:43 AM
PHP search with spaces - by El Forum - 08-26-2012, 01:02 PM



Theme © iAndrew 2016 - Forum software by © MyBB