-1

I ran into a problem that I can't find on Google and now I need your help.

I have a variable that contains values ​​separated by a comma:

$statusValue = "New, Test, Pro, Guru, Master";

And there is a query from the database that receives a list of contacts and contains the status column (only one value is stored in it). How can I extract contacts from the database that contain one parameter from the status value variable in the $statusValue ?

Full Code:

$statusValue = "New, Test, Pro, Guru, Master";
$request = "select * from contacts WHERE status = '$statusValue' ORDER BY id DESC";
$result = mysqli_query($mysql, $request);

I try this: (But it is of course doesn't work) $request = "select * from contacts WHERE status = '$statusValue[]' ORDER BY id DESC";

Pan Roman
  • 1
  • 2
  • If you remove the spaces in `$statusValue` you can just use `select * from contacts WHERE FIND_IN_SET(status, '$statusValue') ORDER BY id DESC` – Nick Aug 17 '23 at 00:36
  • You could just reformat the `$statusValue` string - `$inStr = '\'' . implode('\',\'', explode(', ', $statusValue)) . '\'';` and then - `$query = "SELECT * FROM contacts WHERE status IN ($inStr) ORDER BY id DESC";`. But you should be parameterizing your query [like this](https://onlinephp.io/c/fc5a5). – user1191247 Aug 17 '23 at 09:28

0 Answers0