简体   繁体   English

PHP:使用字符串搜索mysql数据库?

[英]PHP: Search mysql database using a string?

I have a column (attr) in mysql database with values like this: 我在mysql数据库中有一列(attr)值是这样的:

   1- apples, red, big, UK,
   2- Green, apples, big, UK, 
    ETC ETC

Its basically a string of words and they can be in any order as you can see above. 它基本上是一串字,它们可以按照上面的顺序排列。

I want to search inside that column using any given string. 我想使用任何给定的字符串在该列内搜索。 The strings can look like this: 字符串如下所示:

UK, apples, Red, big, 
apples, UK, big, green, 
etc etc

what i need to do is to look into that column and display the results ONLY if the words given in the string matches the exact same words inside that column. 我需要做的是查看该列并仅在字符串中给出的单词与该列中的完全相同的单词匹配时才显示结果。

I've tried using this code: 我尝试使用此代码:

$sql="SELECT * FROM `product_details` WHERE '$list' LIKE CONCAT('%', attr ,'%')";

where the $list is the given strings. $list是给定的字符串。 like: UK, apples, Red, big,

as you can see, the words exist in the database but they are in different ORDER and that is why the PHP doesn't show any result! 如您所见,这些单词存在于数据库中,但它们位于不同的ORDER中,这就是为什么PHP不显示任何结果的原因!

Could someone please advise on this issue? 有人可以建议这个问题吗?

Try to make an array of this 尝试做一个这样的数组

UK, apples, Red, big, 

prepare condition in PHP and than put this data/words like in that topic: 在PHP中准备条件,然后将数据/单词放入该主题中:

Is there a combination of "LIKE" and "IN" in SQL? SQL中是否有“ LIKE”和“ IN”的组合?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM