I have two tables, projects and archive with identical columns. As you understand, I need to archive projects in the archive table, under certain conditions.
I wrote two requests, and they work fine if executed separately, but I’d like to assemble them.
$sql = "INSERT INTO archive (idDocument,documentNumber,submissionDate,projectName)
SELECT idDocument,documentNumber,submissionDate,projectName
FROM projects
WHERE id='".$id."'";
$sql = "DELETE FROM projects
WHERE id='".$id."'";
1/ First of all, how can I assemble these two requests? I keep getting syntax errors.
2/ Now, I assign projects a status (in a column named status) from “1” to “3” in PHP and I’d like to archive these projects two months after they have reached status “3”. How can I do so?
Thank you very much for your help.
Do not know what You mean by assembling, maybe You want to query these two queries in just one simple call, then each query should be ended by query delimiter – a semicolon
;, like this:If You want to archive+delete the projects with status 3 after two months they had been statused by 3, You will have to do these things:
date_changed = NOW()(or similar expression)projectstable and archive + delete all the projects with status 3 wheredate_changedis less then or equal toNOW() - INTERVAL '2' MONTHS…That should do the trick…