参见英文答案 > PHP/Mysql Search – Case sensitive 6个
为用户构建我的搜索引擎以搜索三个变量$Title,$Text和$Number …
如何在用户搜索时找到所有结果,无论用户在$query中键入的案例类型(大写或大写)?
$query = trim ($query);
$raw_results = mysql_query("SELECT * FROM posts
WHERE (`Number` LIKE '%".$query."%') OR (`Title` LIKE '%".$query."%') OR (`Text` LIKE '%".$query."%') ") or die(mysql_error());
解决方法:
用例不敏感collation
SELECT * FROM posts
WHERE (`Number` LIKE '%".$query."%')
OR (`Title` LIKE '%".$query."%')
OR (`Text` LIKE '%".$query."%')
COLLATE utf8_ci --'ci' stands for case insensitive: choose the colaltion that fits your encoding
支持的排序规则列表如下:https://dev.mysql.com/doc/refman/5.5/en/charset-charsets.html