How can I use php array in mysql search query?

I was going to use the scuttle solution at: http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html to process requests on my site. I was wondering how I can take a search from a user and turn it into a single query.

For example, let the user enter “blue dogs” in their search query ... How can I dynamically update the query to include (“blue”, “dog”) in the union and intersection queries?

+3
source share
3 answers

You can do this:

$search_string = implode(',', $search_array);

Now in your request you can use the sentence IN:

$query = "select * from table where field IN ('".$search_string."')";
0

, , , : , SQL-. : PHPManual

+1

for example, your user input is blue dogs, then on the page

$searchstring = "blue dogs"; // or fetch the input
$arr = explode(" ",$searchstring); //this is explode the text by every "space" character

you now have the string entered by the user in the $ arr array, now use it in the request, as usual,

0
source

Source: https://habr.com/ru/post/1745923/


All Articles