ah sorry, here's an example. The following loops through every member in the members table and then selects 3 random members for each member and then stores their email addresses in the variable $emailaddresses. and emails the randomly selected member and the original member telling them.
The bit I'm having trouble with is that the member who has been randomly selected could be sent lots of emails if he's really unlucky. So instead of sending him a seperate email each time I need it to email him once saying the $member variable.:
$query = mysql_query("SELECT * FROM members);
while($member = mysql_fetch_array($query)) {
$emailaddresses = "";
$query2 = mysql_query("SELECT * FROM members WHERE name=RAND() LIMIT 0, 3"

;
while($memberemail = mysql_fetch_array($query2)) {
$emailaddresses .= $memberemail[email];
mail($memberemail[email], "You have been selected", $member[email], $adminemail);
}
mail($member[email], "Main Email", $emailaddresses, $adminemail);
}