Page 1 of 1

Pick-Out/Omit duplicates from a loop

Posted: Thu Mar 23, 2006 2:50 pm
by $var
Hello,

I would like to e-mail all addresses associated within a ticket, except, if their name exists more than once, omit duplicates...
so that everyone only gets one email, instead of the 36 that i got from the tests that i am doing. ;)

What would detect duplicate entries before the loop?

Re: Pick-Out/Omit duplicates from a loop

Posted: Thu Mar 23, 2006 2:53 pm
by Chris Corbyn
$var wrote:Hello,

I would like to e-mail all addresses associated within a ticket, except, if their name exists more than once, omit duplicates...
so that everyone only gets one email, instead of the 36 that i got from the tests that i am doing. ;)

What would detect duplicate entries before the loop?
We really need to see some code that's kinda vague ;)

Where are the email addresses stored? In an array == array_unique(). In MySQL == distinct.

Post the code for your loop ;)

Posted: Thu Mar 23, 2006 2:55 pm
by $var
pardon if this is horribly ugly... i'm not so good coder yet.
thanks for looking in...

Code: Select all

$sql2 = "SELECT COUNT(*) FROM it_assignment WHERE Assign_IID = '$issueID'";
$numrecord = mysql_query($sql2);
$numrecords = mysql_fetch_array($numrecord);
	$intRecsPerPage=100;
		if($_POST["intpage"]=="")
		{
				$intpage=1;
		}
$sql2 = "SELECT * FROM it_assignment WHERE Assign_IID = '$issueID'";
$resultassign = mysql_query($sql2) or die (mysql_error()); 

for($x = (($intpage-1) * $intRecsPerPage); $x < (($intpage-1) * $intRecsPerPage) + $intRecsPerPage; $x++)
	{
		if($x/2 != intval($x/2))
				{
					$bgcolor = "#ffffff";
				}
				else
				{
				$bgcolor = "#F7F7F7";
				}
		if($x >= $numrecords[0])
		{
			break;
		}
	$assignresults = mysql_fetch_array($resultassign);
	$assignTo=$assignresults["Assign_UID"];
	//WHO HAS BEEN INVOLVED WITH TICKET
	$sql3 = "SELECT * FROM it_mem WHERE Mem_ID=".$assignTo;
	$resultAssignTo = mysql_query($sql3) or die (mysql_error()); 
	$AssignToresults = mysql_fetch_array($resultAssignTo);
	$AssignToAddress = $AssignToresults['Mem_Email'];
	$AssignToName = $AssignToresults['Mem_FName'];
	
	// MESSAGE BODY
	$mail_body = " 
	Hello $senderName, 
	This issue has been reassigned to $assignFName $assignLName.
	
	$issueSolution  
	
	------
	Ticket Number: $issueID
	See: $url
	------
	";
	
	// MAIL INFORMATION
	$address = $AssignToAddress.', ';
	$subject = "RE:[$issueID]: $issueTitle";
	$headers = 'From: admin@honeycombworldwide.com' . "\r\n" .
	'X-Mailer: PHP/' . phpversion();
	$headers .= "Reply-To: admin@honeycombworldwide.com\r\n";
	$headers .= "Return-Path: admin@honeycombworldwide.com\r\n";
	$headers .= "CC: cc@honeycombworldwide.com\r\n";
	mail($address, $subject, $mail_body, $headers);
	}

Posted: Thu Mar 23, 2006 3:00 pm
by Chris Corbyn
In this query:

Code: Select all

$sql3 = "SELECT * FROM it_mem WHERE Mem_ID=".$assignTo;
Either change it to:

Code: Select all

$sql3 = "SELECT * FROM it_mem WHERE Mem_ID=".$assignTo." GROUP BY Mem_Email";

//or
$sql3 = "SELECT DISTINCT Mem_Email, Mem_FName FROM it_mem WHERE Mem_ID=".$assignTo;
You're basically asking your query not to return duplicates ;)

Posted: Thu Mar 23, 2006 4:17 pm
by $var
hmmm, i used them both, and it still shows all the e-mails.
this looked way to easy to be possible...

$sql3 = "SELECT * FROM it_mem WHERE Mem_ID=".$assignTo." GROUP BY Mem_Email";
echo shows duplicates.