Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在我的网站上寻找关键字搜索并且遇到了一些困难
$q = "SELECT * from post WHERE post_k like '%".$_GET['s']."%'";
搜索后的网址是website.com/?s=keyword
我没有得到全文搜索。例如,如果我搜索 robin,我可以从 batman 获得结果,因为它们的单词中都有 n。我正在寻找一个搜索,如果我输入 robin,我只会从 robin 获得结果。
谢谢
您需要使用MATCH AGAINSTwith FULLTEXT INDEX。
MATCH AGAINST
FULLTEXT INDEX
CREATE FULLTEXT INDEX search_index ON post (post_k);
那么您的查询将更像(使用 MySQLi 准备好的语句的示例):
$query = $mysqli->prepare("SELECT * FROM post WHERE MATCH(post_k) AGAINST(?)"); $query->bind_param('s', $_GET['s']);