mysql 搜索不带空格

2023-12-14

我的数据库中有一个名称列表,我必须找到在 url 中传递的名称的 id。

我的问题是,我在 url 中传递的名称中不会有空格,而保存的记录将在数据库中。当我搜索数据库时,我没有找到任何记录。

例如,数据库记录是“我的名字”,而我将在 url 中传递并搜索的内容是“我的名字”

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%'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

mysql 搜索不带空格 的相关文章

随机推荐