Here is the code.
function get_autoComplete($tbl, $data, $field, $value, $where='',$group_by=false,$limit=''){
$this->db->select($data);
$this->db->from($tbl);
if($where!=''){
$this->db->where($where);
}
$this->db->like($field, $value);
if($group_by == true){
$this->db->group_by($field);
}
if($limit !='')
{
$this->db->limit($limit);
}
$query=$this->db->get();
return $query->result();
}
In the second select statement, it seems as though like($field, $value)
is case sensitive.
I want it to be insensitive, so I can search without worrying about upper and lower case.
it has something to do with
$this->db->like($field, $value);
It's not consistent. Some will search for the name as is and if it doesn't find it it checks to see if a lower-cased version exists and loads that if it does.
CodeIgniter has a config file that lets you store your database connection values (username, password, database name, etc.). The config file is located at application/config/database. php. You can also set database connection values for specific environments by placing database.
The default character set and collation are latin1 and latin1_swedish_ci, so nonbinary string comparisons are case insensitive by default."
MySQL's queries are case insensitive by default, unless the underlying tables have a case-sensitive collation set.
There is no case insensitive version of the like function. What you can do is transform both sides of the comparison to lower case, so that you take that out of the equation.
like('LOWER(' .$field. ')', strtolower($value))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With