Hello, I have some, given by me, an array of $myarray = array('Керосины', 'Абрикосы', 'Соли', 'Паспорта');
and also I have a database query, find these words from the array there:
$stmt = $pdo->prepare('SELECT * FROM items WHERE itemsname LIKE :iname'); $stmt->execute(Array('iname' => '%'.$iname.'%'));
where the $iname
variable is my attempt to make the correct query $iname = implode(',',$myarray);
In the end, of course, he simply searches for all 4 words together, separated by commas. Now the question is - How to make it look for each word in the array in turn? And put it in some field through a loop, if it coincides? Ie, in the end, I need to do so that by clicking on the yellow button I get the result in the green block below (I can write functionality, I just ask for help with the query and output).
Update (Solution to my problem, thanks for the tip in the answers):
$myarray = array('Керосины', 'Абрикосы', 'Соли', 'Паспорта'); $implod = implode('|',$weaparray); $total = count($myarray); foreach ($myarray as $key => $keyword) { echo '<a href="?type='.$keyword.'" class="iname">'.$keyword.'</a>'; } if (isset($_GET['type'])) { $stmt = $pdo->prepare('SELECT * FROM items WHERE itemsname LIKE :iname'); $stmt->execute(Array('iname' => $_GET['type'].'%')); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { } }
SELECT * FROM table WHERE column1 LIKE ? OR column1 LIKE ? OR column2 LIKE ?
SELECT * FROM table WHERE column1 LIKE ? OR column1 LIKE ? OR column2 LIKE ?
and then insert the data$query->execute(array("%$value1%","%$value2%",.....));
... as one of the options - Alexey ShimanskyREGEXP
?SELECT * FROM items WHERE 1 = (SELECT itemsname REGEXP "val1|val2|val3");
- Alexey ShimanskySELECT * FROM items WHERE itemsname REGEXP "val1|val2|val3";
- Alexey Shimansky