I have built an e-commerce website where the admin can edit the products through MySQL. Now I want to display the edit history of each product. The edit history should contain the ‘date when it was updated’ and ‘what was updated’.
I thought of creating new columns “Edit history” and “Edit Date” inside the product table. Whenever the admin would edit one column, it would get added here.
If anyone knows how to proceed with either this method or some alternative method to solve this issue, please let me know.
Advertisement
Answer
You could create a Trigger in SQL which would allow that if there is a modification you add automatically in your table the data. I let you look at this course if you want : Sql trigger or Sql Trigger. Then you add for the date a Now for the date of the update (the same day) and for the modifications in your trigger add some SQL to see the difference between the before and after. Also, as mentioned above, creating an Audit table would allow you to save your changes. Your triggers would make it easier to add rows. Good luck to you