Jump to content

Connecting db to MailChimp: MySQL query formatting


tower

Recommended Posts

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

post-140578-0-84654300-1361348310_thumb.jpg

Link to comment
Share on other sites

  • 3 weeks later...

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.. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.