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' => 'mailchimp01@mydomain.com', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 1'), array('EMAIL' => 'mailchimp02@mydomain.com', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 2'), array('EMAIL' => 'mailchimp03@mydomain.com', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 3'), array('EMAIL' => 'mailchimp04@mydomain.com', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 4'), array('EMAIL' => 'mailchimp05@mydomain.com', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 5'), array('EMAIL' => 'mailchimp06@mydomain.com', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 6'), array('EMAIL' => 'mailchimp07@mydomain.com', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 7'), array('EMAIL' => 'mailchimp08@mydomain.com', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 8'), array('EMAIL' => 'mailchimp09@mydomain.com', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 9'), array('EMAIL' => 'mailchimp10@mydomain.com', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 10'), array('EMAIL' => 'mailchimp11@mydomain.com', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 11'), array('EMAIL' => 'mailchimp12@mydomain.com', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 12'), array('EMAIL' => 'mailchimp13@mydomain.com', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 13'), array('EMAIL' => 'mailchimp14@mydomain.com', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 14'), array('EMAIL' => 'mailchimp15@mydomain.com', 'FNAME' => 'Mail', 'LNAME' => 'Chimp 15'), ); I have added the two full php files as attachment. example-array.php example-mysqli.php Quote 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('user1@email.tld', 'user2@email.tld', 'user3@email.tld'); $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.. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.