Welcome Guest, Not a member yet? Register   Sign In
how to get the specific match results in for keyword search
#11

[eluser]ashutosh[/eluser]
Now my code is working fine. But it is searching with case sensitive.
i.e if i enter "The" as keywords, then it is showing only the `The` results with uppercase "The", it is not showing the text (i.e the)which are in lower case. How to solve this?

Code:
function suggestions()
{
$this->load->model('Booksmodel');
$term = $this->input->post('term');
    $json_array = $this->Booksmodel->GetAutocomplete($term);
    echo json_encode($json_array);
}


model

Code:
function GetAutocomplete($keyword)
    {
    $this->load->database();    
    $this->db->select('book_title,auth_firstname,isbn,auth_lastname,publisher_name');  
    $this->db->like('book_title', $keyword);
    $this->db->or_like('auth_firstname', $keyword);
    $this->db->or_like('isbn', $keyword);
    $this->db->or_like('auth_lastname', $keyword);
    $this->db->or_like('publisher_name', $keyword);  
    $res = $this->db->get('bookdetails');
    $ret = array();
    foreach ($res->result_array() as $row)
    {
        foreach ($row as $val)
        {
            if (FALSE !== strpos($val, $keyword))
            {
                $ret[] = $val;
                break;
            }
        }
    }
    return $ret;            
    }
#12

[eluser]TheFuzzy0ne[/eluser]
You're not specifying any wildcards in your term:

http://www.tutorialspoint.com/mysql/mysq...clause.htm
#13

[eluser]ashutosh[/eluser]
stripos() - Find the position of the first occurrence of a case-insensitive substring in a string
strrpos() - Find the position of the last occurrence of a substring in a string
strripos() - Find the position of the last occurrence of a case-insensitive substring in a string
strstr() - Find the first occurrence of a string
strpbrk() - Search a string for any of a set of characters
substr() - Return part of a string
preg_match() - Perform a regular expression match




Theme © iAndrew 2016 - Forum software by © MyBB