RLJ Posted February 20, 2011 Share Posted February 20, 2011 Hi all, probably a fairly straightforward question, but I can't find the answer I'm looking for: I have an array 'idents' that contains ID numbers. I now want to write a MySQL query that selects all values of the table-field 'email' where the field 'ID' = any of the IDs stored in 'idents'. Then I want to put those emails in an array 'emails'. So e.g. my table is as follows: ID | email ---------------------- 111111 | email1 222222 | email2 333333 | email3 444444 | email4 555555 | email5 666666 | email6 and the array 'idents' is as follows: '111111','444444','555555' then I want the query to return 'emails' = array('email1','email4','email5'); Thanks for your help! Link to comment https://forums.phpfreaks.com/topic/228306-query-select-email-from-table-where-id-any-from-array/ Share on other sites More sharing options...
Pikachu2000 Posted February 20, 2011 Share Posted February 20, 2011 SELECT FROM . . . WHERE . . . IN() Implode the array into a string with "', '" as the glue, then use that string in the IN() $string = implode("', '", $idents); $query = "SELECT `email` FROM `table` WHERE `id` IN( '" . $string . "')"; Also, since this ends up being more of a php question, moving thread to php coding help . . . Link to comment https://forums.phpfreaks.com/topic/228306-query-select-email-from-table-where-id-any-from-array/#findComment-1177302 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.