Jump to content

Comparing two arrays and sending mail


PattyB

Recommended Posts

Hello,

I am currently trying to build a small mailing list. In the mysql table storing the subscribers info (called members), I have a field called groups. This field is populated from checklists and using serialize to store the values. (I know I shouldnt do it this way, but it has worked for the rest of the mailing list).

I have created the page to send mail and on that the users checks what groups they want to send to. These results are sent to the form with $_POST['groups_input'].

What I need help with is taking the array from the _POST, breaking it down by individual group, and comparing each of those to the array stored in the groups database. If there is a match than it would send the email.

Im guessing to start I need to do something like this to break down the _POST into individual groups and put all the code in between the brackets :

$selected_list = unserialize($groups_selected);
foreach($selected_list as $list_group)
{

}

Im new with all this and help would be very appreciated!
Link to comment
Share on other sites

Something like this?

[code]
<pre>
<?php

$their_POST = array(1, 4, 99);
$database_result = array(
1 => array('aaron', 'bob'),
2 => array('bob', 'laura'),
3 => array('jean', 'john'),
4 => array('jim', 'bill'),
);

foreach ($their_POST as $key => $group_number) {
if (is_array($emails = $database_result[$group_number])) {
echo join(', ', $emails), '<br/>';
}
else {
echo 'Invalid group</br>';
}
}

?>
</pre>

[/code]
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.