LIKE with PDO explode [duplicate]

0

Good evening consecrated, I have a search page, in which I want when someone searches for something like "i3 memory cabinet display" to appear all the items available in the table with respect to these items searched, so I should use the explode in the variable which retrieves the values and put it in LIKE, the problem is there, it creates an array, which I can not know how many values will have depending on the user's search, if I put LIKE '$ variable [0]' it goes and even without the 0 but returns only the first value typed, I would like to know if I have a way to pull the others so that I do not pull the whole table because of an empty array. Follow the Code:

<?php        
$buscaexp = explode(" ",$buscanaurl);
$procura = $conn->prepare("SELECT * FROM produtos WHERE nome LIKE '%$buscaexp[0]%' OR (nome LIKE '%$buscanaurl%')");
    $procura->execute();
?>

follow the link for anyone looking at link

    
asked by anonymous 11.10.2018 / 02:44

1 answer

1

Hi

Try to check if there is a value in position [0]

isset (array [0])

If true, then add in the query string

    
11.10.2018 / 02:49