How to make multiple members of an array match an article in a MySQL single field

Source: Internet
Author: User
How to make multiple members of an array match an article in a MySQL single field.
For example
Array:
$arr =array (' Tom ', ' Cat ', ' jam ', ' Tim ', ' Bim ');


The contents of the article fields in MySQL are as follows
First string
Tom,cat,tony,girl

Second string
Jam,tim,bim

Third string
Jam,tom

Fourth string
Tool,wood,boy,cat


Through this array, how to match all the following four lines
------to solve the idea----------------------
$sql = ' Create temporary table T ';
foreach ($arr as $i = = $v) {
$sql. = $i? "Union Select ' $v '": "Select ' $v as name";
}
mysql_query ($sql); Create a temporary table

$sql = "SELECT * from Tbl_name, T where Find_in_set (T.name, Tbl_name.field)";
$rs = mysql_query ($sql); Inquire

------to solve the idea----------------------
If the query is more full-text search, the most direct and fast,
Besides, your words are separated by commas, so the word breaker is especially easy.
------to solve the idea----------------------
The following string is converted into an array, compared to the above array, and if the array has the same element, the current string is recorded.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.