ClemenzoDK Posted May 20, 2011 Share Posted May 20, 2011 Hello, I have some issues selecting multiple rows, and yes I'm new to both MySQL and PHP. The query is as following: SELECT *, CONCAT(locations.zip_code, ' ', locations.city) as location from locations, locations_associations where locations.zip_code = locations_associations.zip_code AND client_id = 1; The query works just fine, but the thing is that I have multiple client_id's stored in a PHP array which I also need to know the location of. My logic tells me that the easiest way to insert multiple client_id's into the query, would be to implode the array and then insert each client_id into the query including a seperator of some sort. The alternative would be to create an loop that inserted a client_id one at a time, which seems like a long way around contra imploding. Anyway, is it possible in this case to put in multiple client_id's in the query, and how should they be seperated, I've tried with a comma like this: SELECT *, CONCAT(locations.zip_code, ' ', locations.city) as location from locations, locations_associations where locations.zip_code = locations_associations.zip_code AND client_id = 1, 2, 3, 4; Which gives me an error. Thanks in advance. Btw, I'm running MySQL 5.5.8 on my local machine. Link to comment https://forums.phpfreaks.com/topic/236955-issues-selecting-multiple-rows/ Share on other sites More sharing options...
gristoi Posted May 20, 2011 Share Posted May 20, 2011 there is a bult in function in mysql that allows you to pass in an array as a parameter: $array = (1,2,3,4); SELECT *, CONCAT(locations.zip_code, ' ', locations.city) as location from locations, locations_associations where locations.zip_code = locations_associations.zip_code AND client_id IN ($array); Link to comment https://forums.phpfreaks.com/topic/236955-issues-selecting-multiple-rows/#findComment-1217978 Share on other sites More sharing options...
ClemenzoDK Posted May 20, 2011 Author Share Posted May 20, 2011 Thanks for the quick answer, gristoi, works just perfect! Link to comment https://forums.phpfreaks.com/topic/236955-issues-selecting-multiple-rows/#findComment-1217981 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.