我的数据库中有一个名单列表,我必须找到我在网址中传递的名称的ID.
我的问题是,我在url中传递的名称将不会有空格,而保存的记录将在数据库中.当我搜索数据库时,我没有找到任何记录.
例如,数据库记录是"我的名字",而我将在网址中传递并搜索的是"myname"
if(isset($_GET["name"])) $name = $_GET["name"];
SELECT id
FROM table
WHERE name Like '%$name%'
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
// 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%'
Run Code Online (Sandbox Code Playgroud)