Forum Moderators: coopster
Now, 1200+ entries into this mess, I want to get rid of any duplicate entries. I know that I could just do a simple SELECT and group by the name, address and phone number (the three main fields that would determine if an entry is duplicate or not) and if there is more than 1 result, then delete one or more of the entries. Sounds simple, sure. However, I'm not really sure how to go about this. I don't have any code, so if you have any ideas, please help me out.
$double = array();
$unique = array();$sql = "SELECT id, unique_1, unique_2, unique_3 FROM table";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_assoc($result)) //retrieve the results
{
//let's combine these three fields into one.
$temp = $row['unique_1'] . "_" . $row['unique_2'] . "_" . $row['unique_3'];
if(in_array($temp, $unique)) $double[] = $row['id']; //if is in array, then put it to deletion
else $unique[] = $temp;//else add it to unique list
}
//now prepare the records for deletion - I would test this many times before moving further
$ids_to_delete = implode(",", $double);$sql = "DELETE FROM table WHERE id IN($ids_to_delete)";
Hope this helps you!
Michal