Jump to content


Photo

Comparing two arrays and sending mail


  • Please log in to reply
1 reply to this topic

#1 PattyB

PattyB
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 14 September 2006 - 04:41 PM

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!

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 14 September 2006 - 05:15 PM

Something like this?

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


Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users