Here is a table
Id Date Name vendor
1 | 123 | jungle | qwe
2 | 43 | jungle | qwe
3 | 678 | jungle | ewq
4 | 678 | jungle | ewq
5 | 678 | jungle | ewq
6 | 678 | jungle | hgjghj
This script removes rows from the table that have duplicate values in the name column and also have the same vendor value. Leaving only one unique row. The script is also executed via XHR ajax call $.post()
, after clicking a button on the front end.
$sql = DELETE x
FROM $table x
JOIN
( SELECT vendors
, email
, MIN(lead_id) min_lead_id
FROM $table
WHERE vendors = $vendor
GROUP BY vendors
, email
) y
ON y.vendors = x.vendors
AND y.email = x.email
AND y.min_lead_id <> x.lead_id;
mysql_query($sql, $conn);
echo json_encode($foo);
and the result
Id Date Name vendor
1 | 123 | jungle | qwe
3 | 678 | jungle | ewq
6 | 678 | jungle | hgjghj
Now with a table of 50k it finishes in two seconds. Or rather, it returns an ajax call via the echo json_encode($result);
. Now at that point I assume the process is complete but after going into my mysql table and refreshing again and again, I find out that mysql is still running because the total number of rows reported in the table keeps changing as if its still running query.
How do I make echo json_encode($result);
wait until the database is finished updating? Or is there a better way to resolve this? Thanks.
$("#complete_dedupe").live("click", function(e) {
e.preventDefault();
table_name = $('#IMEXp_import-selectTable-select option:selected').val();
$.post("dedupevendor.php", {"table": table_name}, function(data) {
count_dedupe = 0;
count_dedupe = data;
$("#dupe_vendor").append(count_dedupe);
$("#tr2").fadeIn("slow");
vendor = $("#vendor_hidden").val();
$("#edit_par4").append(vendor);
}, "json")
});
By continually refreshing phpmyadmin, the circled number changes for the duration of about less than a minute. This only happens right after I run my dedupe script and right after the script already returns from the ajax call. The picture is below