You just need to join the semicolon identifiers:
$myarray = new array('D1', 'D5', 'D8'); $str = ""; foreach ($myarray as $item) { $str .= $item . ","; } $str = rtrim($str, ","); $query = "DELETE * FROM groupdentlink WHERE group_id = 'a' AND dentist_id NOT IN ($str)";
This will give you this request:
DELETE * FROM groupdentlink WHERE group_id = 'a' AND dentist_id IS NOT IN (D1, D5, D8);
If you need quotes around identifiers, modify the loop as follows:
foreach ($myarray as $item) { $str .= "'".$item . "',"; }
swatkins
source share