电子邮件列表,从表中删除行

发布于 2024-12-08 01:27:35 字数 143 浏览 0 评论 0原文

如果我在 .txt 文件中有电子邮件帐户列表,有没有办法可以针对表中包含电子邮件帐户的行的每个实例执行 mysql 删除语句?

我们有一个时事通讯邮件列表,其中大约有 600 封电子邮件目前无效,我们希望有一种更简单的方法来删除它们,除了手动逐一删除之外。

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 around 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

怀中猫帐中妖 2024-12-15 01:27:35

使用 Excel 将数据集转换为逗号分隔的字符串,然后简单地:

DELETE FROM YOUR_TABLE
WHERE email IN ('[email protected]', '[email protected]') 

请注意,您还需要在 Excel 中的每个电子邮件地址之前和之后手动添加单引号。

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

DELETE FROM YOUR_TABLE
WHERE email IN ('[email protected]', '[email protected]') 

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

影子是时光的心 2024-12-15 01:27:35

假设您想使用文本文件的内容作为要从数据库中删除的地址源:

$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());
}

是最简单的形式。您可以采取一些措施来优化流程,例如以引号/逗号分隔的形式创建电子邮件列表,并使用 WHERE IN (...) 代替,以减少生成的查询数量/被执行。

请注意,我使用 PHP 作为伪代码占位符,但基本原理在几乎任何语言中都是相同的。

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.

夏花。依旧 2024-12-15 01:27:35

单个电子邮件创建删除语句然后使用Microsoft Excel完成其余电子邮件怎么样?通过使用连接功能并与所选电子邮件列表进行匹配

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文