needs_upgrade Posted April 11, 2010 Share Posted April 11, 2010 Hello guys! I want to make a query like this: SELECT service_id FROM services WHERE service_id NOT IN ( 4, 6, 8, 12) but the values in the "NOT IN" clause will be taken from an array from a group of checkboxes. This is my code: <?PHP $pid_array = $_POST[pid]; $sql = 'SELECT service_id FROM services WHERE service_id NOT IN ('; foreach ($pid_array as $service_id) { $sql .= "".implode(", ", $service_id).""; } $sql .= ')'; mysql_query($sql); ?> It says : Warning: implode() [function.implode]: Invalid arguments passed Thanks guys Link to comment https://forums.phpfreaks.com/topic/198187-problem-using-foreach-and-implode-functions/ Share on other sites More sharing options...
teamatomic Posted April 11, 2010 Share Posted April 11, 2010 implode wants an array not a string. Your foreach loops an array giving a string each loop. skip the foreach and feed implode the pid array. HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/198187-problem-using-foreach-and-implode-functions/#findComment-1039914 Share on other sites More sharing options...
needs_upgrade Posted April 11, 2010 Author Share Posted April 11, 2010 ok. i'll try that. thanks teamatomic Link to comment https://forums.phpfreaks.com/topic/198187-problem-using-foreach-and-implode-functions/#findComment-1039928 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.