I am trying to make a simple yet effective search function for my site, with both a basic and advanced search setup. The search engine does in theory work, it just outputs my entire table from the database on both occasions. I am using CodeIgniter since it has a lot of flexibility. And below you can find my code snippets.
Simple Search
PHP Code:
function doSearch()
{
$search_String = $this->input->post('Search');
$this->db->select('*')->from('content')->like('short_version', $search_String);
$query = $this->db->get();
if($query->num_rows() == 0){
$this->refinedSearch($search_String);
}
else{
$this->showResults($query->result_array());
}
}
Advanced Search
PHP Code:
function advSearch(){
$search_string = $this->input->post('keywords');
$where = $this->input->post('catagory');
$refined = $this->input->post('what');
echo $where;
$this->db->select('*')->from('content')->where('cat_id',$where)->like($refined,$search_string);
$query = $this->db->get();
echo $query->num_rows();
if($query->num_rows() == 0){
$data['content'] = "<h1>No Results Found!</h1>";
$data['content'] .= "<p> You searched for ". $search_string ." has yeilded no results";
}
else{
$this->showResults($query->result_array());
}
}
And my output is generic since they both use the same output page
PHP Code:
private function showResults($array){
$result_loop['result_loop'] = $array;
$data['content'] = $this->parser->parse('dynamic/search/results',$result_loop,TRUE);
$this->parser->parse('dynamic/empty_page',$data);
}
So any Ideas on how to make this work correctly? In my head right now, it looks like when I do an advanced search in the title field with a keyword of dud, it should come up and say, Sorry No Search Results found. etc. But it shows all the contents of the table I am searching. And I have 7 records in it right now with no Dud in the title box. Even when I try Hosting, which is 1 row in my table I still get all 7 results.
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
|