[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>
<?php else:?>
<?php if (count($results)):?>
<p><?php echo count($results) ?> result(s) returned for query: <?php echo $_POST['search_query'];?></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