tower Posted February 20, 2013 Share Posted February 20, 2013 I'm trying to connect a database with MailChimp. I'm using a script that needs to receive the data (first name, email) in a specific format. Since the data is only available in a very unusual way I have no clue how to get it out in the required formatting. I have added a screen of the table. First Name and Email are connected with a PID. The required formatting is: $cols = array( 'first_name' => 'FNAME', 'email' => 'EMAIL', ); $selectQuery = 'SELECT email, first_name FROM `user`'; $existsQuery = 'SELECT COUNT(id) FROM `user` WHERE email = ?'; There's also an example with an array: $users = array( array('EMAIL' => '[email protected]', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 1'), array('EMAIL' => '[email protected]', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 2'), array('EMAIL' => '[email protected]', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 3'), array('EMAIL' => '[email protected]', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 4'), array('EMAIL' => '[email protected]', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 5'), array('EMAIL' => '[email protected]', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 6'), array('EMAIL' => '[email protected]', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 7'), array('EMAIL' => '[email protected]', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 8'), array('EMAIL' => '[email protected]', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 9'), array('EMAIL' => '[email protected]', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 10'), array('EMAIL' => '[email protected]', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 11'), array('EMAIL' => '[email protected]', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 12'), array('EMAIL' => '[email protected]', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 13'), array('EMAIL' => '[email protected]', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 14'), array('EMAIL' => '[email protected]', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 15'), ); I have added the two full php files as attachment. example-array.php example-mysqli.php Link to comment https://forums.phpfreaks.com/topic/274720-connecting-db-to-mailchimp-mysql-query-formatting/ Share on other sites More sharing options...
mweldan Posted March 8, 2013 Share Posted March 8, 2013 assuming table named tl_formdata_details is where you will pull data from.. you can put emails in an array , and firstnames in another array. then you can form another array with required formatting. <?php $fnames = array('user1', 'user2', 'user3'); $emails = array('[email protected]', '[email protected]', '[email protected]'); $result = array(); for($i=0;$i<count($fnames);$i++) { $result[] = array( 'EMAIL' => $emails[$i], 'FNAME' => $fnames[$i], 'LNAME' => 'CHIMP '.$i); } echo '<pre>'; print_r($result); echo '</pre>'; ?> there must be another way to achieve this. just some idea.. Link to comment https://forums.phpfreaks.com/topic/274720-connecting-db-to-mailchimp-mysql-query-formatting/#findComment-1417609 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.