gpt4 book ai didi

php - 搜索建议 - PHP - MySQL

转载 作者:行者123 更新时间:2023-11-29 08:52:18 24 4
gpt4 key购买 nike

我有一个 MySQL 查询如下;

$query = "SELECT * FROM dictionary WHERE word LIKE '%".$word."%' ORDER BY word LIMIT 10";

这将在我的字典数据库中搜索(并显示)单词。

搜索将返回;

醉了就醉了,等等,等等.. ,醉酒醉酒,等等,等等..醉酒醉酒,等等,等等..

但它不会为 Drunkin 返回 Drunken。我想将这个词显示为建议词(就像我们在谷歌中看到的那样)。我怎样才能做到这一点?

下面是我的完整代码供引用;

$db = new pdo("mysql:host=localhost;dbname=dictionary", "root", "password");
$query = "SELECT * FROM dictionary WHERE word LIKE '%".$word."%' ORDER BY word LIMIT 10";
$result = $db->query($query);
$end_result = '';
if ($result) {
while ( $r = $result->fetch(PDO::FETCH_ASSOC) ) {
$end_result .= $r['word'].'<br>';
}
}
echo $end_result;

最佳答案

尝试使用 SOUNDEX

Soundex keys have the property that words pronounced similarly produce the same soundex key, and can thus be used to simplify searches in databases where you know the pronunciation but not the spelling. This soundex function returns a string 4 characters long, starting with a letter.

以下是一些关于 SO 的问题,可以引导您走向正确的方向:

希望这有帮助。

关于php - 搜索建议 - PHP - MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10849902/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com