A little background...
I have a database of names (addresses, etc) that was created by importing information from two sources. Unfortunately, some of the data (names, etc) are duplicates (ex: John Smith has 2 records). I'm now trying to clean up the database to eliminate the duplicates. Adding to the mix, each of "John Smiths" records contain parts of data that are "more accurate," so its not as simple as deleting 1 record and leaving the other.
I have written a script that displays all names in the database where a duplicate exists. The name with the lower "ID" need to have the address, city, state, zip, phone, and email fields copied FROM it, and essentially pasted TO the record with the higher ID - leaving all other fields in the higher ID record untouched. I have created a button next to the name on the list, so when clicked, I want it to automatically perform this action between those two semi-duplicate records.
The script I've written to do that looks like this...
// HANDLE MERGE
if(!empty($_GET['mergeID'])){
$db = myDatabase::getInstance();
$sql = "SELECT * FROM classlist WHERE FirstName='$_GET[mergeFirstName]' AND LastName='$_GET[mergeLastName]' AND ID!='$_GET[mergeID]'";
$result = $db->Execute($sql) or die($sql."<p>".$db->ErrorMsg());
$copy_ID = $row['ID'];
// LOAD THE RECORD WITH A HIGHER ID BASED ON THE SEARCH PERFORMED ABOVE
if(is_numeric($_GET['mergeID']))
$data->loadById('$copy_ID');
// UPDATE WITH GET VALUES FROM LOWER ID RECORD
$data->Address1=stripslashes('$_GET[mergeAddress1]');
$data->City=stripslashes('$_GET[mergeCity]');
$data->State=stripslashes('$_GET[mergeState]');
$data->Zip=stripslashes('$_GET[mergeZip]');
$data->Phone=stripslashes('$_GET[mergePhone]');
$data->Email=stripslashes('$_GET[mergeEmail]');
}
$data->save();
What I am trying to do here is
1) Load the record with the lower ID field (the ID is transferred as part of a GET)
2) Load the record with the higher ID field (essentially by finding the duplicate name WHERE id != $_GET['mergeID'])
3) Copy the Address1, City, State, Zip, Phone, Email fields from the lower ID record, TO the higher ID record.
Thus far I've had no luck and am getting a little frustrated. There are no error messages, the script just doesn't do anything.
Any advice??
If I'm on the complete wrong track, could you please get me headed in the direction I need to be going? Maybe I'm making this too difficult!
Thank you in advance!