March 24, 2012
Select where in array
Question by Jordy
How can I select all records where the id is in the array?
So if I have an array with the values 1,25,2,12,1859 and 192: all the records with the id’s should be returned.
Now I have this:
$query="SELECT * FROM table WHERE Id IN(".implode(",",$my_array).")";
But that doesn’t work. It only returns one value.
Answer by Starx
Add the quotes in the query
$query="SELECT * FROM table WHERE Id IN('".implode("','",$my_array)."')";