0

I have an array like this:

$myArray = array(1,2,3,5,4,7,8);

I want to select records where id is IN() $myArray. how do i achieve something like this in the SQL? IN('1','2','3','5','4','7','8') so that each of the element is like a separate string

what am currently doing is not helping:

$SQL = "SELECT id FROM users WHERE id IN(".IMPLODE(',',$myArray).")";
james Oduro
  • 673
  • 1
  • 6
  • 22
  • 1
    try this answer http://stackoverflow.com/a/907821/5608642 – Fahmi B. Feb 10 '17 at 07:20
  • 1
    Possible duplicate of [passing a php array into an sql query](http://stackoverflow.com/questions/7298216/passing-a-php-array-into-an-sql-query) – dhruv jadia Feb 10 '17 at 07:22
  • 3
    Possible duplicate of [PHP/MySQL using an array in WHERE clause](http://stackoverflow.com/questions/907806/php-mysql-using-an-array-in-where-clause) – LF00 Feb 10 '17 at 07:29

1 Answers1

0

Try this:

$SQL = "SELECT id FROM users WHERE id IN('" .implode("','", $myArray) . "')";
                                         ^            ^ ^                ^
Calos
  • 1,783
  • 19
  • 28