开发者

List of emails, delete rows out of a table

If I have a list of of email accounts in a .txt file, is there a way I can perform a mysql delete statement for each instance of the rows that contain the email account against a table?

We have a newsletter mailing list which aroun开发者_高级运维d 600 emails are currently invalid, and we want an easier way of getting rid of them besides manually going in one by one to do it.


Use excel to turn the dataset into a comma separated string and then simply:

DELETE FROM YOUR_TABLE
WHERE email IN ('example@aol.com', 'example2@aol.com') 

Note that you will need to manually add the single quotes before and after each email address in excel as well.


Assuming you want to use the text file's contents as the source of addresses to delete from the database:

$addreses = file('emails.txt');
foreach($addresses as $address) {
    $safe_address = mysql_real_escape_string($address);
    $sql = "DELETE FROM yourtable WHERE (email = '$safe_address');";
    $result = mysql_query($sql) or die(mysql_error());
}

is the simplest form. You can do some things to optimize the process, such as creating a list of emails in quoted/comma-separated form and using WHERE IN (...) instead, to reduce the number of queries generated/executed.

Note that I'm using PHP as a pseudo-code placeholder, but the basic principle would be the same in pretty much any language.


What about create the delete statement for single email then use Microsoft excel to complete the rest of the emails? by using the concatenate function and matching with the list of the selected emails

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜