Check for duplicates
| From: | Murph | Date: | Wed, 29 Nov 2000 23:31:56 +0000 |
| Subject: | Check for duplicates | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-27924@lists.php.net to get a copy of this message | ||
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