php mysql jquery AJAX 自动完成区分大小写
在我的 php 脚本中,
$names = $_GET['part'];
$result = mysql_query("SELECT * FROM namestable where names LIKE'%$names%' LIMIT 10");
while ($row = mysql_fetch_assoc($result)) {
$colors[]=$row['publishers'];
}
检查匹配并且运行良好。
但是假设我的表有一个名字 Alfred,只有当我输入 Alfr
时才会出现该建议,而如果我输入 alfr
则不会出现该建议
In my php script,
$names = $_GET['part'];
$result = mysql_query("SELECT * FROM namestable where names LIKE'%$names%' LIMIT 10");
while ($row = mysql_fetch_assoc($result)) {
$colors[]=$row['publishers'];
}
checks for matches and works well.
But suppose my table has a name Alfred, the suggestion will appear only if i type Alfr
and not appearing if i type alfr
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用不区分大小写的排序规则(例如
utf8_general_ci
),您提供的示例将起作用。 (有关详细信息,请参阅 MySQL 字符集支持手册部分。 )或者,您可以简单地使用 LOWER函数如下:
顺便说一句,如果您试图捕获简单大小写更改之外的差异,您还可以使用 MySQL 的 SOUNDEX 函数获取并查找听起来相似的字符串的匹配项。
顺便说一句,您需要在 $names 变量上使用 mysql_real_escape_string ,或者(更好)通过 mysqli 或 PDO 接口使用准备好的语句。
The example you've provided will work if you're using a case insensitive collation such as
utf8_general_ci
. (See the MySQL Character Set Support manual section for more information.)Alternatively, you could simply use the LOWER function as follows:
Incidentally, if you're attempting to catch differences beyond simple case changes, you could also use MySQL's SOUNDEX function to obtain and find a match for strings that sound similar.
Incidentally, you need to use mysql_real_escape_string on your $names variable, or (better still) use prepared statements via the mysqli or PDO interfaces.