在 MySQL 数据库字段中搜索多个文本 [英] Search a MySQL DB field for multiple text

查看:61
本文介绍了在 MySQL 数据库字段中搜索多个文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有以下内容将在我的数据库中搜索一个字段以提及一个词,但想知道是否有可能如果客户输入两个词,而不是只输出与该特定格式匹配的任何内容,它实际上将单词拆分并返回两个不完全匹配的单词的结果:

I currently have the following that will search a field within my db for a mention of one word, but would like to know if it is possible that if a customer enter two words, rather than only output anything matching that particular format, it actually splits the words up and returns the result for both words not an exact match:

目前有

   WHERE title LIKE '%SEARCH TEXT HERE%'..

因此,如果用户当前输入FISH"或FISH FOOD",那么它将仅返回包含该文本的列.

so if a user currently enter 'FISH' or 'FISH FOOD' then it will return only the columns that have that text within in it as it is.

我希望发生的是,如果他们输入了多个单词,那么它实际上会将其拆分,然后搜索并返回所有单独单词的结果.

What i would like to happen is if they entered more than one word then it actually splits that up and then searches and returns the results for all the separate words.

因此,'FISH FOOD' 将返回带有单词 fish 或 food 的所有行,而不仅仅是任何与 'FISH FOOD' 匹配的行

So 'FISH FOOD' would return all rows with the word fish or food with in and not just anything that matched 'FISH FOOD'

使用 PHP 和 MySQL

Using PHP and MySQL

谢谢

推荐答案

将搜索字符串拆分为多个部分 (explode(" ", $string)).然后为每个部分添加一个条件标题 LIKE "%$part%' OR title LIKE "%$part%' OR ...

Split your search string into parts (explode(" ", $string)). Then add for each part a condition title LIKE "%$part%' OR title LIKE "%$part%' OR ...

这篇关于在 MySQL 数据库字段中搜索多个文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆