<?php
// Duplicate entries remover from database
// task :: load url check if more than 2 entries exists replace it with new entry
session_start();
// no time limit
set_time_limit(0);
// connect to db
include ("config.php");
// select data from database target woth and domain table
$result = mysql_query( "SELECT * FROM domain" ) // table domain wwww.domain.com
or die("SELECT Error: ".mysql_error());
$resultx = mysql_query( "SELECT * FROM worth" ) // table worth domain.com
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_query($result); // Loading table domain
$num_rowsx = mysql_query($resultx); // Loading table worth
//duplicate url counter
$dcounter=0;
// fetching data
while ($get_infox = mysql_fetch_assoc($resultx) && $get_info = mysql_fetch_assoc($result))
{
// Loading Urls for Comparing
$wurl=$get_infox[domain]; // Loading url from table worth
$idx=$get_infox[id]; // Loading Id of table worth
$durl=$get_info[domain]; // Loading url from table domain
if ($durl != $wurl[domain]) // Comapring Table 'Domain' Url With All Urls of Table 'worth'
{
// Load id too
// use id to separate domains
// let id = $id;
if ($wurl == $wurl[domain] && $idx != $idx[id]) // Comapring one Url With All Urls of Table 'worth'
{
//$dcounter++; // ++ dcounter mean matched found its should be 2 or greater becusae 1 is itself
//if($dcounter == 2)
//{
mysql_query("INSERT INTO worth (domain) VALUES ('".$durl."') WHERE domain='".$wurl."'"); // insert
echo "url $durl replacement success Replaced by".$durl.".<br>";
mysql_query("DELETE FROM domain WHERE domain='".$durl."'");
//}
if($dcounter == 1)
{
echo "url checked and ok <br>"; // no multiple match so ok
}
}
}
}
mysql_close($con); // close connection to database
?>
i have large database so i cant remove duplicate remove manually
so i write little code for it but not working properly
my task ::
i have one table worth there i have two columns id and domain now i have to find duplicate entries in it by checking for domain column if 2 same domain column values then duplicate entry , after that i have to replace one of these two entries with new value to domain column .
so little confuse please help