Created
March 23, 2012 19:55
-
-
Save niczak/2174340 to your computer and use it in GitHub Desktop.
CSV Contact Generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // database connection/retrieval code removed | |
| $sCSV = NULL; | |
| while($aRes = pg_fetch_assoc($rRes)) | |
| { | |
| // first, middle, last, suffix, company, department, | |
| // title, bus. street, bus. city, bus. state, bus. zip, | |
| // bus. country, home street, home city, home state, home zip, | |
| // home country, bus. fax, bus. phone, bus. phone 2, home phone, | |
| // mobile phone, email | |
| // $sCSV .= sprintf("'%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s'\n", | |
| $sCSV .= sprintf("\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"\n", | |
| $aRes['sfirst'], | |
| !empty($aRes['smiddle1']) ? $aRes['smiddle1'] : "", | |
| $aRes['slast'], | |
| !empty($aRes['ssuffix']) ? $aRes['ssuffix'] : "", | |
| !empty($aRes['sprefix']) ? $aRes['sprefix'] : "", | |
| !empty($aRes['snick']) ? $aRes['snick'] : "", | |
| "Desert Research Institute", | |
| !empty($aRes['saffil']) ? $aRes['saffil'] : "", | |
| !empty($aRes['stitle1']) ? $aRes['stitle1'] : "", | |
| !empty($aRes['soffst1']) ? $aRes['soffst1'] : "", | |
| !empty($aRes['soffcity1']) ? $aRes['soffcity1'] : "", | |
| !empty($aRes['soffstate1']) ? $aRes['soffstate1'] : "", | |
| !empty($aRes['soffzip1']) ? $aRes['soffzip1'] : "", | |
| "United States of America", | |
| !empty($aRes['shome_streeta1']) ? $aRes['shome_streeta1'] : "", | |
| !empty($aRes['shome_city1']) ? $aRes['shome_city1'] : "", | |
| !empty($aRes['shome_state1']) ? $aRes['shome_state1'] : "", | |
| !empty($aRes['shome_zip1']) ? $aRes['shome_zip1'] : "", | |
| "United States of America", | |
| !empty($aRes['sofffax1']) ? $aRes['sofffax1'] : "", | |
| !empty($aRes['soffphone1']) ? $aRes['soffphone1'] : "", | |
| !empty($aRes['soffphone2']) ? $aRes['soffphone2'] : "", | |
| !empty($aRes['shome_phone1']) ? $aRes['shome_phone1'] : "", | |
| !empty($aRes['scell1']) ? $aRes['scell1'] : "", | |
| !empty($aRes['semail_dri']) ? $aRes['semail_dri'] : "", | |
| !empty($aRes['semail_alt']) ? $aRes['semail_alt'] : "" | |
| ); | |
| } | |
| // for quick and dirty file creation do the following | |
| // php dump.php > dump.csv from the CLI | |
| printf("%s", $sCSV); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment