RLJ Posted January 2, 2011 Share Posted January 2, 2011 Hi all, I have an array with (an undetermined number of) variables stored in it. I want to write a MySQL query that SELECTS FROM table WHERE "some column" = "any value from the array" So, say the array is as follows: $thearray = array('Apples','Bananas','Pears'); then I want a query that is equivalent to: $sql= mysql_query (" SELECT * FROM table WHERE (columnX = 'Apples' OR columnX = 'Bananas' OR columnX = 'Pears') ") But it has to work for any size array. Pls help! Thanks. Link to comment https://forums.phpfreaks.com/topic/223169-selectfrom-table-where-columnx-any-value-from-array/ Share on other sites More sharing options...
Pikachu2000 Posted January 2, 2011 Share Posted January 2, 2011 SELECT . . . WHERE . . . IN() "SELECT * FROM table WHERE field IN( "'. implode("', '", $array) . "')"; Link to comment https://forums.phpfreaks.com/topic/223169-selectfrom-table-where-columnx-any-value-from-array/#findComment-1153703 Share on other sites More sharing options...
RLJ Posted January 2, 2011 Author Share Posted January 2, 2011 Cheers! Link to comment https://forums.phpfreaks.com/topic/223169-selectfrom-table-where-columnx-any-value-from-array/#findComment-1153970 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.