Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用数组中的where-like或like查询mysql数据库?_Mysql_Sql_Database - Fatal编程技术网

如何使用数组中的where-like或like查询mysql数据库?

如何使用数组中的where-like或like查询mysql数据库?,mysql,sql,database,Mysql,Sql,Database,如何使用where-like(数组)或like(数组)查询mysql数据库 尝试使用或 SELECT * FROM table WHERE field like '%ietm1%' OR field like '%item2%' OR field like '%item3%' <?php $sql = array('0'); // Stop errors when $words is empty $words =array('df','sdfds',

如何使用where-like(数组)或like(数组)查询mysql数据库

尝试使用

SELECT * FROM table WHERE field like '%ietm1%' OR field like '%item2%' OR field like '%item3%' 
        <?php

    $sql = array('0'); // Stop errors when $words is empty

    $words =array('df','sdfds','dsfdsf');

    foreach($words as $word)
    {
        $sql[] = 'field  LIKE %'.$word.'%';
    }

    $sql = 'SELECT * FROM table WHERE '.implode(" OR ", $sql);

    echo $sql;

    ?>

SELECT * FROM table WHERE field like '%ietm1%' OR field like '%item2%' OR field like '%item3%' 
        <?php

    $sql = array('0'); // Stop errors when $words is empty

    $words =array('df','sdfds','dsfdsf');

    foreach($words as $word)
    {
        $sql[] = 'field  LIKE %'.$word.'%';
    }

    $sql = 'SELECT * FROM table WHERE '.implode(" OR ", $sql);

    echo $sql;

    ?>


USE IN子句查询
SELECT*FROM table WHERE field IN(ietm1,item2,item3)
USE IN子句查询,但它只返回精确匹配为什么不使用。这是一个由谷歌公司拥有的网络搜索引擎。请尽量不要回答通过简单的网络搜索很容易得到答案的问题。