Split array into seperate groups by common ID to use as 'dynamic' variable

hominid4

Member
Hi. I have a 'client-emails' list/table that contains a Client ID and email addresses that are assigned to those, each client can have several assigned emails.

'client-emails'
client_id | email
============
27 | email1@client27domain
27 | email2@client27domain
42 | email1@client42domain
42 | email2@client42domain
42 | email3@client42domain
46 | email1@client46domain

I have a second table that is used to send out emails to the above emails:
'client-messages'
id | client_id | message
============


For the 'client-messages' form email we're needing to personalize these emails per client ID, within the "To" field and "message" field. The problem I'm having is a 'client_id' having multiple assigned emails.

I'm needing to split each client_id group of emails per client, and when the email sends it knows which group of comma separated array of emails to have in the "To" field per client_id, and a placeholder variable within the email body that dynamically pulls each respective Client ID based on which emails.

To: $clientEmails
Message:
Your Client ID is: $clientId.


i.e.,
To: email1@client27domain,email2@client27domain
Message:
Your Client ID is: 27


Could I get a push in the right direction with querying the 'client-emails' table, and dynamically split the group of emails and implode them within the "To:" field for each respective client dynamically? I'm thinking if I can get that figured out then doing a dynamic ClientId placeholder variable within the Message should fall in place.
 
Use the 'Email to (eval)'.

Code:
$clientId = '{client_messages___client_id_raw}';
if (!empty($clientId)) {
   $myDb = JFactory::getDbo();
   $myQuery = $myDb->getQuery(true);
   $myQuery->select('email')->from('client_emails')->where('client_id = ' . $myDb->quote($clientId));
   $myDb->setQuery($myQuery);
   $myEmails = $myDb->loadColumn();
   return implode(',', $myEmails);
}
else {
   return '';
}

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top