PHP + MySQL - 搜索脚本(全文)?

时间:2022-09-19 19:15:36

I would like to ask for help with this task: I have a MySQL table with structure like this:

我想请求帮助完成这项任务:我有一个MySQL表,其结构如下:

author                name        year       description
Bernard Cornwell      Azincourt   2009       Publisher XY, good condition

Now I would like to have MySQL Query which returns result (searches the book) on various inputs (like these):

现在我希望MySQL Query能够在各种输入上返回结果(搜索书籍)(如下所示):

  • Cornwell
  • Azincourt
  • Cornwell Azincourt
  • Azincourt Cornwell
  • Cornwell Azincourt 2009
  • Cornwell Azincourt 2009

  • Bernard Cornwell Azincourt
  • Bernard Cornwell Azincourt

  • Azincourt

Do I have to add Fulltext index on every column and then on author, name, year, description?

我是否必须在每一列上添加全文索引,然后在作者,姓名,年份,描述上添加?

1 个解决方案

#1


0  

Are you looking for something like this?

你在找这样的东西吗?

Select * From TableName WHERE description LIKE "%searchvalue%";

This query will return rows where the description contains whatever you put for the search value. The percent signs act as a wild card so it will return any row that has the search value in the description field, even if there is other text in the field. If you want it to be an exact math you could just do this simple query.

此查询将返回描述包含您为搜索值放置的内容的行。百分号表示外卡,因此即使字段中还有其他文本,它也会返回描述字段中具有搜索值的任何行。如果你想要它是一个精确的数学,你可以做这个简单的查询。

Select * From TableName WHERE description = "searchvalue";

As far as putting it into a PHP script you would just assign the search term to a variable and then use that variable in your query.

只要将其放入PHP脚本中,您只需将搜索项分配给变量,然后在查询中使用该变量即可。

#1


0  

Are you looking for something like this?

你在找这样的东西吗?

Select * From TableName WHERE description LIKE "%searchvalue%";

This query will return rows where the description contains whatever you put for the search value. The percent signs act as a wild card so it will return any row that has the search value in the description field, even if there is other text in the field. If you want it to be an exact math you could just do this simple query.

此查询将返回描述包含您为搜索值放置的内容的行。百分号表示外卡,因此即使字段中还有其他文本,它也会返回描述字段中具有搜索值的任何行。如果你想要它是一个精确的数学,你可以做这个简单的查询。

Select * From TableName WHERE description = "searchvalue";

As far as putting it into a PHP script you would just assign the search term to a variable and then use that variable in your query.

只要将其放入PHP脚本中,您只需将搜索项分配给变量,然后在查询中使用该变量即可。