0

I have a MySQL database on my web host holding a database of users. Within that database I store the email addresses of all customers. I have a customer list and a marketing list. I send out quarterly newsletters and have created a Outlook "mail rule" to gather returned/bounced messages. I then run a script that scans that folder of returned/bounced messages and gathers the email addresses to export to an excel spreadsheet.

Now that I have the list of email addresses I want to run a search command in phpMyAdmin to search the database for that list so I can delete them.

I know Excel can export the list comma separated but I can not figure out how to search the database for multiple entries. I was thinking that is a way to search for any of the following: first@email.com, second@email.com, third@email.com, etc..... and the result would show every response and I can then just "select all" to remove the entry from the database.

Does anyone have any ideas on how to do this?

Kevin Reid
  • 37,492
  • 13
  • 80
  • 108

1 Answers1

1

I would write a script (PHP is my fav lang), that read the file and split by the newlines, then joined them back up again with ',' delimiters. Finally, I'd execute a DELETE FROM command.

Something like this:

<?php
$emails = "'".implode("','", explode("\n", file_get_contents('my_csv_file.csv')))."'";
$db->query("DELETE FROM table_name WHERE email IN (".$emails.")");
?>
  • Will that leave left over junk in the database? The reason I was thinking about choosing "select all" after displaying the results is that I will be able to delete the entire customer. Each customer has a table for: firstname / lastname / email /subscribed / code / store_id – user2360421 May 08 '13 at 01:30
  • Yes, if you don't delete associated table entries, it will leave junk in the database. You'd have to select all the primary keys from table_name and then delete all related entries in other tables. –  May 08 '13 at 02:00
  • Is there a simple way to just list the results and then I can select all to delete the entire customer? – user2360421 May 08 '13 at 04:55
  • Don't know what you mean by "just list the results". –  May 08 '13 at 23:56