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.
Add the quotes in the query
$query="SELECT * FROM table WHERE Id IN('".implode("','",$my_array)."')";
My suggestion is to first implode the my_array, store it in a variable and use is inside your query.
Example:
<?php
$my_array[0] = 24;
$my_array[1] = 26;
$qryVals = implode(",",$my_array);
$query="SELECT * FROM table WHERE Id IN($qryVals)";
echo $query;
?>