RE: [PHP] Check for duplicates

From: Date: Thu, 30 Nov 2000 02:12:04 +0000
Subject: RE: [PHP] Check for duplicates
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-27950@lists.php.net to get a copy of this message
Would it be valid to remove all duplicates from the table? To find if you have duplicate entries, you can do something like: select EMAIL_ADDRESS, count(*) from CONTACTS group by EMAIL_ADDRESS having count(*) > 1 This will show all entries in the CONTACTS table with more than one entry for the same email address. So, choose whatever column would be a duplicate identifier and put it in your "select" statement and the group by part. > -----Original Message----- > From: Murph [mailto:murph@murphatnight.com] > Sent: Thursday, 30 November 2000 09:32 > To: php-general@lists.php.net > Subject: [PHP] Check for duplicates > > > Hi. I have a database of just over 1200 names and addresses where I know > there are some duplicates in it. The server seems to choke on the > following > code and I wonder if anyone has any suggestions. I get an "Internal Server > Error" after processing about 300 MySQL records in this way: > > <?php > > $db = mysql_connect("www.myserver.com", username, password) OR DIE("Unable > to connect to database"); > mysql_select_db("databasename",$db); > > function find() > { > > global $processname; > global $processid; > global $realname; > set_time_limit(0); > > $checksql = "SELECT * FROM tablename ORDER BY mailid"; > $checkresult = mysql_query($checksql) or die ("Can't pick the current > record up"); > > if ($checkrecord = mysql_fetch_array($checkresult)); > { > do > { > $thisrecord = strtoupper(trim($checkrecord["email"])); > $thisid = $checkrecord["mailid"]; > > if ($processname == $thisrecord && $processid != $thisid) > { > echo "<FONT SIZE=\"1\"><B>Check #" . $processid . > " (" . > $realname . ") " . "and #" . $thisid . " (" . > $checkrecord["email"] . > ")!</B></FONT><BR>"; > } > } > while ($checkrecord = mysql_fetch_array($checkresult)); > mysql_free_result($checkresult); > } > } > > > $sql = "SELECT * FROM tablename ORDER BY mailid"; > $result = mysql_query($sql) or die ("What, I can't even grab a > record?!?"); > > if ($myrow = mysql_fetch_array($result)) > { > $count = 0; > do > { > $processname = strtoupper(trim($myrow["email"])); > $processid = trim($myrow["mailid"]); > $realname = $myrow["email"]; > echo "<FONT SIZE=\"1\">Checking #" . $processid . ": > " . > $myrow["email"] . " against the database.<BR></FONT>"; > find($processid); > } > while ($myrow = mysql_fetch_array($result)); > mysql_free_result($result); > } > > ?> > > > > www.murphatnight.com > __________________________________________________________________ > Brian Murphy - 193A Lowell St., Apt. 24 - Methuen, MA 01844 - > (978) 725-6654 > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#27950) next »