如何使用数组中的where-like或like查询mysql数据库?
如何使用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',
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子句查询,但它只返回精确匹配为什么不使用。这是一个由谷歌公司拥有的网络搜索引擎。请尽量不要回答通过简单的网络搜索很容易得到答案的问题。