我想请求帮助完成这项任务:
我有一个MySQL表,结构如下:
author name year description
Bernard Cornwell Azincourt 2009 Publisher XY, good condition
现在我想让MySQL Query在各种输入上返回结果(搜索书)(如下所示):
>康沃尔
> Azincourt
> Cornwell Azincourt
> Azincourt Cornwell
> Cornwell Azincourt 2009
> Bernard Cornwell Azincourt
> Azincourt
我是否必须在每个列上添加全文索引,然后在作者,名称,年份,描述上添加?
解决方法:
你在找这样的东西吗?
Select * From TableName WHERE description LIKE "%searchvalue%";
此查询将返回描述包含您为搜索值放置的内容的行.百分号表示外卡,因此即使字段中有其他文本,它也会返回描述字段中具有搜索值的任何行.如果你想要它是一个精确的数学,你可以做这个简单的查询.
Select * From TableName WHERE description = "searchvalue";
只要将其放入PHP脚本中,您只需将搜索项分配给变量,然后在查询中使用该变量即可.
标签:php,mysql,search,full-text-search
来源: https://codeday.me/bug/20190711/1432717.html