How do i query mysql database using where like (array) or like (array)?
Asked
Active
Viewed 519 times
-3
-
USE IN CLAUSE QUERY – JYoThI May 30 '16 at 09:56
-
`SELECT * FROM table WHERE field IN (ietm1,item2,item3)` – Amani Ben Azzouz May 30 '16 at 09:58
-
USE IN CLAUSE QUERY BUT IT RETURN ONLY EXACT MATCHES – JYoThI May 30 '16 at 10:04
-
Why don't you use [Google](http://google.com). It is a web search engine owned by Google Inc. – Peyman Mohamadpour May 30 '16 at 11:17
1 Answers
0
TRY TO USE OR
SELECT * FROM table WHERE field like '%ietm1%' OR field like '%item2%' OR field like '%item3%'
OR
<?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;
?>

JYoThI
- 11,977
- 1
- 11
- 26
-
1Please try not to answer questions which can easily get answered doing a simple web search. – Peyman Mohamadpour May 30 '16 at 11:21