MySQL搜索没有空格 [英] mysql search without spaces
本文介绍了MySQL搜索没有空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在数据库中有一个名称列表,我必须找到在URL中传递的名称的ID.
I have a list of names in my database and I have to find the id of the name that I pass in the url.
我的问题是,我在url中传递的名称中没有空格,而保存的记录将在数据库中.当我搜索数据库时,找不到任何记录.
My problem is that the names I pass in the url will not have a space in them while the saved record will in the database. When I search the database I get no records found.
例如,数据库记录为我的名字",而我将在url中传递和搜索的内容为我的名字"
e.g database record is "My Name" while what I will be passing in the url and searching with is "myname"
if(isset($_GET["name"])) $name = $_GET["name"];
SELECT id
FROM table
WHERE name Like '%$name%'
感谢您的帮助.
推荐答案
// id don't know the exact syntax, but this is what you are searching for I guess:
// replace spaces with nothin temporarily, then check equal (=) not like (%%) if name is exactly the same (except the spaces)
SELECT id, REPLACE(name, ' ', '') AS tmp FROM table WHERE tmp='%$name%'
这篇关于MySQL搜索没有空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文