我知道只使用LOWER和strlower可以解决问题。但我面临的问题是语法,因为我使用数据表库,他们没有设置它不敏感所以我需要做一点更新。
上次它为我工作
like('LOWER(' .$field. ')', strtolower($value));
但现在主查询是
$sWhere .= $this->select[$mColArray[$i]] . " LIKE '%" . $sSearch . "%' OR ";
所以我尝试了这个
$sWhere .= $this->select[."LOWER(".$mColArray[$i].")".] . " LIKE '%" . strtolower($sSearch) . "%' OR ";
但我对这种表示法不满意,请任何人帮助我,因为我得到错误...
此行来自以下函数的Ignited-dataTables Library。
protected function get_filtering()
{
if($this->check_mDataprop())
$mColArray = $this->get_mDataprop();
elseif($this->ci->input->post(mysql_real_escape_string('sColumns'))){
$mColArray = explode(',', $this->ci->input->post('sColumns'));
$mColArray = array_filter($mColArray);
if(empty($mColArray)){
$mColArray = $this->columns;
}
}
else
$mColArray = $this->columns;
$sWhere = '';
$sSearch = mysql_real_escape_string($this->ci->input->post('sSearch'));
$mColArray = array_values(array_diff($mColArray, $this->unset_columns));
$columns = array_values(array_diff($this->columns, $this->unset_columns));
if($sSearch != '')
for($i = 0; $i < count($mColArray); $i++)
if($this->ci->input->post('bSearchable_' . $i) == 'true' && in_array($mColArray[$i], $columns))
$sWhere .= $this->select[$mColArray[$i]] . " LIKE '%" . $sSearch . "%' OR ";
$sWhere = substr_replace($sWhere, '', -3);
if($sWhere != '')
$this->ci->db->where('(' . $sWhere . ')');
for($i = 0; $i < intval($this->ci->input->post('iColumns')); $i++)
{
if(isset($_POST['sSearch_' . $i]) && $this->ci->input->post('sSearch_' . $i) != '' && in_array($mColArray[$i], $columns))
{
$miSearch = explode(',', $this->ci->input->post('sSearch_' . $i));
foreach($miSearch as $val)
{
if(preg_match("/(<=|>=|=|<|>)(\s*)(.+)/i", trim($val), $matches))
$this->ci->db->where($this->select[$mColArray[$i]].' '.$matches[1], $matches[3]);
else
$this->ci->db->where($this->select[$mColArray[$i]].' LIKE', '%'.$val.'%');
}
}
}
foreach($this->filter as $val)
$this->ci->db->where($val[0], $val[1], $val[2]);
}
答案 0 :(得分:2)
解决了问题。搜索工作,现在不敏感。新规范。
protected function get_filtering()
{
if($this->check_mDataprop())
$mColArray = $this->get_mDataprop();
elseif($this->ci->input->post(mysql_real_escape_string('sColumns'))){
$mColArray = explode(',', $this->ci->input->post('sColumns'));
$mColArray = array_filter($mColArray);
if(empty($mColArray)){
$mColArray = $this->columns;
}
}
else
$mColArray = $this->columns;
$sWhere = '';
$sSearch = mysql_real_escape_string($this->ci->input->post('sSearch'));
$mColArray = array_values(array_diff($mColArray, $this->unset_columns));
$columns = array_values(array_diff($this->columns, $this->unset_columns));
if($sSearch != '')
for($i = 0; $i < count($mColArray); $i++)
if($this->ci->input->post('bSearchable_' . $i) == 'true' && in_array($mColArray[$i], $columns))
$sWhere .= "UPPER(".$this->select[$mColArray[$i]] . ") LIKE '%" . strtoupper($sSearch) . "%' OR ";
$sWhere = substr_replace($sWhere, '', -3);
if($sWhere != '')
$this->ci->db->where('(' . $sWhere . ')');
for($i = 0; $i < intval($this->ci->input->post('iColumns')); $i++)
{
if(isset($_POST['sSearch_' . $i]) && $this->ci->input->post('sSearch_' . $i) != '' && in_array($mColArray[$i], $columns))
{
$miSearch = explode(',', $this->ci->input->post('sSearch_' . $i));
foreach($miSearch as $val)
{
if(preg_match("/(<=|>=|=|<|>)(\s*)(.+)/i", trim($val), $matches))
$this->ci->db->where($this->select[$mColArray[$i]].' '.$matches[1], $matches[3]);
else
$this->ci->db->where('UPPER('.$this->select[$mColArray[$i]].') LIKE', '%'.strtoupper($val).'%');
}
}
}
foreach($this->filter as $val)
$this->ci->db->where($val[0], $val[1], $val[2]);
}
我改变了
$sWhere .= $this->select[$mColArray[$i]] . " LIKE '%" . $sSearch . "%' OR ";
进入
$sWhere .= "UPPER(".$this->select[$mColArray[$i]] . ") LIKE '%" . strtoupper($sSearch) . "%' OR ";
和 改变
$this->ci->db->where($this->select[$mColArray[$i]].' LIKE', '%'.$val.'%');
进入
$this->ci->db->where('UPPER('.$this->select[$mColArray[$i]].') LIKE', '%'.strtoupper($val).'%');
答案 1 :(得分:0)
尝试包括第三个参数 FALSE in where condition
例如: -
$ this-&gt; ci-&gt; db-&gt; where($ this-&gt; select [$ mColArray [$ i]]。'LIKE','%'。$ val。'%' ,FALSE 强>);
答案 2 :(得分:0)
使用MySQL
- 使用MySQL的任何其他内容都不区分大小写(所有排序规则之间存在一些差异)。
在您的情况下,如果您操作“常规”字符,则应使用utf8_general_ci。旁注:通过这种整理,德语ß将成为搜索查询中的“ss”(对于其他特殊字符也是如此)。
但是,如果您希望整个列/表为utf8_bin(区分大小写)但是您仍然希望对单个查询不区分大小写,则可以在查询中指定它
SELECT * FROM table WHERE name LIKE 'something' COLLATE utf8_general_ci
(如果更改排序规则,则需要更改列本身,而不仅仅是表格)
要更改列:
ALTER TABLE tblname ALTER COLUMN name varchar(100) COLLATE utf8_general_ci