Hello,
I am trying to develop a script that would go through a delete duplicate records in a mysql db. I dont want to do the native mysql de-dupicate to new db as that loses indexing and the db is fairly large.
What i tried to do is have it compare the titles of a record and then delete the one with the higher id. It currently prints both the first record and the matching duplicate, but it doesnt seem to actually execute the delete statement as when i go into phpmyadmin i can still see the record. I dont get any errors which is adding to my frusturation.
I hope it is just something simple i am not thinking about that someone more experienced than me can figure out.
I GREATLY appreciate your help!!!
Here is what i have:
$mysql=new MySQL();
$sql="select * from news where left(source_id,1)='b' order by id";
$result=$mysql->query($sql);
print $result->size();
print "<br><br>";
$i=0;
while($row=$result->fetch())
{
//$t=addslashes(substr($row['title'],0,30));
$row['title']=addslashes($row['title']);
$sql="select * from news where title like '$row[title]%' and id>'$row[id]' order by news.id";
$result2=$mysql->query($sql);
while($row2=$result2->fetch() and strlen($row['title'])>20)
{
print "$row[title] ******************** $row[id]<br>";
print "$row2[title] ############### $row2[id]<br>------------------<br><br>";
$sql="delete from news where id='$row2[id]'";
$i++;
}
}
print $i;