Welcome Guest, Not a member yet? Register   Sign In
Search function
#1

[eluser]junaids[/eluser]
i am trying to develop a search function. but i am getting wrong search results.
heres my controller
Code:
function search_communities()
  {
          $results = $this->searchmodel->search_communities($this->input->post('search_query'));
        $data['results'] = $results;
        $this->load->view('search/search_result', $data);
  
}
and model
Code:
function search_communities($search_query)
    {
    $this->db->select('*');
    $this->db->from('community');
    $this->db->where('Community_name', '$search_query');
    $Q = $this->db->get();
    if ($Q->num_rows() > 0) {
        return $Q->result();
       } else {
         return FALSE;
    }
}
and view
Code:
<?php if (empty($_POST['search_query'])):?>
<p>No search query submitted.</p>
&lt;?php else:?&gt;
    &lt;?php if (count($results)):?&gt;
<p>&lt;?php echo count($results) ?&gt; result(s) returned for query: &lt;?php echo $_POST['search_query'];?&gt;</p>
there are only two records in community table. but whatever is submit query , it returns a result. i have also tried the $this->db->like statement but it also gives the same result. any suggestions


Messages In This Thread
Search function - by El Forum - 06-23-2009, 01:03 PM
Search function - by El Forum - 06-23-2009, 01:07 PM
Search function - by El Forum - 06-23-2009, 01:13 PM
Search function - by El Forum - 06-23-2009, 01:19 PM
Search function - by El Forum - 06-23-2009, 01:28 PM
Search function - by El Forum - 06-23-2009, 01:43 PM
Search function - by El Forum - 06-23-2009, 01:49 PM
Search function - by El Forum - 06-23-2009, 02:03 PM
Search function - by El Forum - 06-23-2009, 02:11 PM
Search function - by El Forum - 06-23-2009, 03:28 PM



Theme © iAndrew 2016 - Forum software by © MyBB