Pick-Out/Omit duplicates from a loop

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Pick-Out/Omit duplicates from a loop

Post 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?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Pick-Out/Omit duplicates from a loop

Post 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 ;)
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post 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);
	}
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 ;)
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post 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.
Post Reply