[eluser]rich.a.coy[/eluser]
Hello,
I'm trying to make a relatively simple search form but my query is not working as expected. Below is my code. I've only been using CI and MVC for about 3 weeks.
What do I need to add to make the query not case sensitive? Right now searching for "rich" does not return the "Richard" or "Rich" that are there and properly returned if searched for with "Rich"
Thanks in advance any help you can offer.
(I've stripped out the unessential code from the sections below.)
The form to enter the search term :
Code:
<form action="search" method="post"><input name="searchbox" type="text" value=""/><input type="submit" value="Search"/></form>
The Search Controller:
Code:
function index()
{
$query = array();
// Get search results
if($query = $this->search_model->search_results())
{
$data['matches'] = $query;
}
$this->load->view('app/app_template', $data);
}
The Search Model:
Code:
function search_results() {
$search_term = $this->input->post('searchbox');
if ($search_term != "") {
$sql = "SELECT * FROM user_profiles WHERE fname LIKE '%".$this->db->escape_like_str($search_term)."%'";
$query = $this->db->query($sql);
return $query->result();
}
}
Finally, the Search View:
Code:
<h3>Your Search Results</h3>
<?php if(isset($matches)) : foreach($matches as $row) : ?>
<h2><?php echo $row->fname; ?></h2>
<?php endforeach; ?>
<?php else : ?>
<h2>No Matches Found.</h3>
<?php endif; ?>
</div>