0

I have a PHP array and what I am trying to do is use that in my MySQL query to select only the ones that are in the array.

I have this:

SELECT * FROM table IN ('.implode(',', $array).')

I guess what needs to happen is I need quotes around each array item for this to work. Right now it just has one, two, three, four where it should be "one", "two", "three", "four"

How could I do that? Or is there another way to do what I am looking for?

Thanks!

Drew
  • 6,736
  • 17
  • 64
  • 96
  • check this link you can find your answer [http://stackoverflow.com/questions/907806/php-mysql-using-an-array-in-where-clause][1] [1]: http://stackoverflow.com/questions/907806/php-mysql-using-an-array-in-where-clause – Arun Kumar Oct 16 '11 at 01:56
  • I hope you've remembered to pass the strings in your array through [`mysql_real_escape_string()`](http://php.net/mysql-real-escape-string) first. – Ilmari Karonen Oct 16 '11 at 03:29

1 Answers1

4

This would do it,

"'" . implode("','", $array) . "'"
imm
  • 5,837
  • 1
  • 26
  • 32