I’m contemplating on a small script in php mysql to delete a row if it exists in the database but doesn’t exist in the update.
Please let me know if i’m going in the right direction.
Heres what happens…
An uploaded file from which i get the information with all data, it is then Inserted to the mysql database, or updated if already exists.
What i’m trying to do is if the uploaded file doesn’t have whats in the database (as it’s been updated) then Delete the row what is there.
AGENT_REF in the database is the Primary Key
$sql_archeck = mysql_query ("SELECT AGENT_REF FROM epsales");
while($check = mysql_fetch_array($sql_archeck) {
if ($check["AGENT_REF"] == $agentref) {
}
}
I hope i’ve explained clearly, my head not on right today..lol
Thank you for your time with this and any assistance is highly appriciated!
UPDATE
For eg, say the file uploaded has info as:
AGENT_REF = 1
AGENT_REF = 2
AGENT_REF = 3
AGENT_REF = 5
but in the database:
AGENT_REF = 1
AGENT_REF = 2
AGENT_REF = 3
AGENT_REF = 4
AGENT_REF = 5
I want to Delete AGENT_REF 4 from the database 🙂
Hope this update helps Thank you!
array_diff() is your friend.
http://php.net/manual/en/function.array-diff.php
EDIT: changed post from MYSQL’s ON DUPLICATE KEY UPDATE answer to PHP array_diff() solution after reading comments on other posts explaining full requirement…