prepare('SELECT * FROM overview WHERE msgid=:messageid'); $articles = array(); $i = 0; foreach ($msgid_list as $msgid) { $msgid = trim($msgid); $query->execute(['messageid' => $msgid]); echo "Searching: " . $msgid . "\n"; while (($row = $query->fetch()) !== false) { echo "Found in: " . $row['newsgroup'] . "\n"; $articles[$i]['msgid'] = $msgid; $articles[$i]['newsgroup'] = $row['newsgroup']; $i++; } } $dbh = null; foreach ($articles as $article) { delete_message($article['msgid'], $article['newsgroup']); }