$duper = mysql_query("SELECT * FROM `data_f` ORDER BY `id` ASC",$dbc2);
while($dupea = mysql_fetch_assoc($duper)){
$id = $dupea['id'];
$a = $dupea['find'];
$b = $dupea['found'];
//dupes?
mysql_query("DELETE FROM `data_f` WHERE `find` = '$a' AND `found` = '$b' AND `id` != '$id'",$dbc2) or die(mysql_error());
mysql_query("DELETE FROM `data_f` WHERE `found` = '$a' AND `find` = '$b' AND `id` != '$id'",$dbc2) or die(mysql_error());
}
This is um... working. But it appears to be removing a lot more records than I expected.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
If I looped through those 3 records, I would want the script to delete record #3 because it is a duplicate of record number one (except the fields are reversed)
So if I were looking to delete "duplicates" of record # 1 I would want to delete the obvious duplicate, which would be an excact duplicate of the row (except for id)
DELETE FROM `table` WHERE `found` = 1 AND `find` = 2 AND `id` != '$currentid'
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
$numf1 = mysql_query("SELECT count(*) AS `num1` FROM `data_f` WHERE `find` = '$theperson'") or die(mysql_error());
$numf2 = mysql_query("SELECT count(*) AS `num2` FROM `data_f` WHERE `found` = '$theperson'") or die(mysql_error());
$fid_result = mysql_query("SELECT DISTINCT `find` AS `user` FROM `data_f` WHERE `found` = '$theperson' UNION SELECT DISTINCT `found` AS `user` FROM `data_f` WHERE `find` = '$theperson'") or die(mysql_error());
I come up with 281 results.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Thanks for the code aborint, but unfortunately that systematically deleted all records.
But, after 7 headaches, and 3 days.. I came up with this script that does what I want. Forgive the variable naming, but after dealing with this for so long, i used the shortest ones possible.
$r = mysql_query("SELECT `id` FROM `users` ORDER BY `id` ASC",$dbc2);
while($a = mysql_fetch_assoc($r)){
$r2 = mysql_query("
SELECT `id` AS `id_field`,`find` AS `user` FROM `data_f` WHERE `found` = '{$a['id']}'
UNION
SELECT `id` AS `id_field`,`found` AS `user` FROM `data_f` WHERE `find` = '{$a['id']}'
",$dbc2) or die(mysql_error());
$a3 = array();
while($a2 = mysql_fetch_assoc($r2)){
$a3[$a2['id_field']] = $a2['user'];
}
$test = array_unique($a3);
if(count($test) > 0){
$ids = array_keys($test);
$ids_list = implode(',',$ids);
mysql_query("DELETE FROM `data_f` WHERE `id` NOT IN($ids_list) AND `find` = '{$a['id']}'",$dbc2) or die(mysql_error());
mysql_query("DELETE FROM `data_f` WHERE `id` NOT IN($ids_list) AND `found` = '{$a['id']}'",$dbc2) or die(mysql_error());
}
}
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.