gpt4 book ai didi

PHP MYSQL 按出现的字数对搜索结果进行排序

转载 作者:行者123 更新时间:2023-11-30 23:04:09 25 4
gpt4 key购买 nike

我知道如何进行常规的 php mysql 搜索并显示结果。然而,由于我想要完成的事情的性质,我需要能够计算列中出现的世界,并将结果从最高到最低排序。让我更好地解释一下:

例如我的查询是:任何无害的东西。

第一个结果:

find words: 3
id: 12
NAME: self [harmless]
DESCRIPTION: [Anything] that happens.[Anything]that, in happening, causes itself.

第二个结果:

find words: 5
id: 55
NAME: Data mining area
DESCRIPTION: This the extraction [harmless] of knowledge significant [harmless] newly-hired faculty [harmless]in order to [Anything] development [Anything].

第三个结果:

find words: 1
id: 9
NAME: Programming php sql
DESCRIPTION: the [Anything] members to perform their tasks .

他们将按以下方式排名/显示:(基于找到的单词数)。

查找单词:5

id: 55
NAME: Data mining area
DESCRIPTION: This the extraction [harmless] of knowledge significant [harmless] newly-hired faculty [harmless]in order to [Anything] development [Anything].

查找单词:3

id: 12
NAME: self [harmless]
DESCRIPTION: [Anything] that happens.[Anything]that, in happening, causes itself.

查找单词:1

id: 9
NAME: Programming php sql
DESCRIPTION: the [Anything] members to perform their tasks .

我希望我已经解释得足够好,请。求助,我真的不知道该怎么办。我不擅长 php。如果你能给我一个代码或步骤,我很感激。非常感谢你。

this is my query: (simplified version)
$query = mysql_query("SELECT thesis_id,thesis_name,thesis_abstract
FROM thesis
WHERE enabled = 1 AND
MATCH(thesis_name,thesis_abstract) AGAINST('$find' IN BOOLEAN MODE)
OR thesis_name LIKE '%$find%' OR thesis_abstract LIKE '%$find%'
")
while($data=mysql_fetch_array($query))
{
echo $data['thesis_id'];
echo $data['thesis_name'];
echo $data['thesis_abstract'];
}

最佳答案

我认为您需要创建您的自己的 worldcount 函数 以填充“found words”列的值,然后使用 usort() 函数来获取它按此列排序

关于PHP MYSQL 按出现的字数对搜索结果进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22578806/

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