Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert an array into format for an WHERE IN mysql clause [duplicate]

I have an array that contains strings

e.g array('14183f6c-9bf5', '074306fb-6eaf')

I want to convert this into a format readable for an mysql query with an IN statement but I keep getting issues as its a string..

Essentially get this to be formatted as such in my sql query - I am using implode but to no avail.. any ideas

Guid IN ("14183f6c-9bf5", "074306fb-6eaf")

$Guids = array('14183f6c-9bf5', '074306fb-6eaf');
$csv = implode('",', $Guids);
like image 300
Zabs Avatar asked Nov 05 '25 12:11

Zabs


1 Answers

Try something like this

$whereIn = implode('","', $array);
$sql = 'SELECT * FROM table WHERE col IN ("'.$whereIn.'")';
like image 86
krzysiej Avatar answered Nov 08 '25 09:11

krzysiej



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!