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' => '[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

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

  • 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('[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.. 

Archived

This topic is now archived and is closed to further replies.

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