District 25
NEBridge - Email Documentation: CSV File from Database

1. Lists for MailChimp can be made from any .csv (comma-separated values) file that contains a column for email addresses. Most lists are made directly from the database using SQL (structured query language) commands executed in phpMyAdmin. The Best in Class file is populated by a program on the database menu. Occasionally lists are made from files received from outside sources such as the ACBL.

2. To create a .csv file from the database:

2.1 Sign on to the version of the database that has the most accurate players table. Currently the “email,” “oktoemail,”and “familiar_name” fields are only updated on the remote version on the iPower server.

2.2 On the top line of the main iPower Screen click on the word “Hosting”.

2.3 On the main Hosting screen click on the words "MySQL Management" in the grey area on the left.

2.4 On the MySQL Management screen click on the word "Manage" associated with the database. The database is currently named mikestuff1.

2.5 On the Database Management screen click on the word "phpMyAdmin" associated with your user name, in this case "mike".

2.6 The main phpMyAdmin page consists of one narrow column on the left and a much wider column on the right. Select the database by clicking on its name (in this case mikestuff1) at the top of the left column. A list of the tables and views is then displayed beneath the name, and the appearance of the right side also change dramatically. Yes, you should specify the database even though the program appears to know what it is.

2.7 SQL statements can be keyed in on the textbox on this screen, which is produced by clicking on the SQL button above the wide right column. Usually, however, it is a good idea to start with a SQL statement that has already been written and tested. Many of these are stored in text files on the local server in a folder named "scripts" under Bridge/District 25/Database. For the most part, the files are named after the primary table or view used in the scripts. The extension is always .txt.

2.8 Let us assume that we want to send an email to all active players who attended the Ocean State Regional in 2017. The file on the local server named attendance.txt has several queries that are similar to this requirement. Three of them are shown above. 

2.9 The second of the three SQL statements shown in step 2.7 has been copied from the text file and pasted into the textbox for SQL statements.

2.10 To make the sequel statement match the requirements, the following changes were implemented. 

2.10.1 The “select” statement was changed to use the view named actives instead of D25_actives, which only includes players currently in District 25.

2.10.2 The designation for cal_year in the “where” statement for the attendance table was changed from >= 2016 (greater than or equal to 2016) to = 2017. 

2.10.3 The tournament name (the field named abbrev) in the “where” statement for the attendance table was changed to specify only one abbrev, Ocean St., instead of three possible suggestions. Spelling must be exact. A query with 'Ocean St' without the period would have a valid syntax, but no records would be selected.

2.10.4 Notes on the four fields selected in the first line:

2.10.4.1 The familiar_name is often used in the salutation of the message. It is mapped to the First Name field on the MailChimp audience.

2.10.4.2 The email field is the key field (unique identifier) on every MailChimp list. If two players have the same email address, the second one will be ignored. This happens fairly frequently with people from the same family.

2.10.4.3 The name_town_key field provides an almost unique way to identify players. The player number would be absolutely unique, but an extra step would be involved in looking up the player's information.

2.11 The  phpMyAdmin program will not accept SQL statements that have syntactic errors. For example, every open parenthesis and quotation mark must be matched by a closing parenthesis/quotation mark. However, acceptance is no guarantee that the statement does not guarantee that the statement will select all the records that you want and no others. It is easy to make mistakes during this process. Listing all of the possible problems and their solutions is beyond the scope of this article. Many excellent articles have been posted on the Internet concerning MySQL syntax. Dr. Google is your friend.

2.12 If the statement contains no syntactic errors, the list of selected records will appear beneath a listing of the SQL statement. At the top will be a report of how many records were selected.

2.13 If the number of records seems reasonable, and no errors are apparent in the records that were selected, click on the word “Export” on the last line on the page, NOT the one a few lines higher at the bottom of the list. That one requires that you specify individual records to export.

2.14 On the screen shown above make sure that the radio button for "Quick" is selected Then use the pull-down menu under "Format:" to select "CSV:". Click on the “Go” button in the lower left. The SQL statement will be executed. 

2.15 iPower will download the file to the folder on your local computer that is designated for downloads. What happens next varies according to what browser you are using. If you are using Firefox, you should click on the grey area in the top right part of the web page that contains a downward pointing arrow and a bracket that is on its side. Then a line showing actives.csv will appear in a white box beneath it. There may also be other lines from other downloads that you have done, but the top line is always the download just completed. If you are using another browser, you will need to figure out how to find where actives.csv is located. 

2.15.1 Right-click on "actives.csv" and select "cut" to put the file into the clipboard. 

2.15.2 In another window use Windows Explorer or whatever the Apple equivalent is to find the folder named "MailChimp/D25 Uploads/YYYY", where YYYY is the year. If you have not made a subfolder for the event, do so.

2.15.3 Use Ctrl V to paste actives.csv into the folder for the event.

2.15.4 Right-click on actives.csv, select "Rename", and change the file name to something descriptive of the selection criteria.

2.15.5 Remember where you saved the file. Write it down if necessary. This is the file that is used in step #3.6 of the instructions for creating a new list, which is posted here.