3

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);
Zabs
  • 13,852
  • 45
  • 173
  • 297

2 Answers2

5

Try something like this

$whereIn = implode('","', $array);
$sql = 'SELECT * FROM table WHERE col IN ("'.$whereIn.'")';
linktoahref
  • 7,812
  • 3
  • 29
  • 51
krzysiej
  • 889
  • 9
  • 22
0

try with this :

$whereIn = '("' . implode('","', $array) . '")';
Halayem Anis
  • 7,654
  • 2
  • 25
  • 45