View Single Post
Old 11-12-2012, 05:11 AM   PM User | #10
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
Yes, i have to keep a history of all changes made in the dB
Finally! That is what I have been asking you since my first post.

Okay...truly simple:

Say you have a table named Questions that has fields such as questionNumber and questionText and maybe points.

SO you simply create another table named QuestionsHistory with those same fields but ADDING fields whenChanged and changedBy and then, before you change any given Questions records you do:
Code:
INSERT INTO QuestionsHistory
SELECT NOW(), $idOrNameOfPersonMakingChange, * 
FROM Questions WHERE questionNumber = $numberOfQuestionBeingChanged
NOTE: Because of the peculiarities of MySQL, you should put the *ADDED* fields *FIRST* in the QuestionsHistory table. It makes the above query easier to write.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.

Last edited by guelphdad; 11-12-2012 at 02:16 PM.. Reason: fixed bold tag
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
salmanmanekia (11-12-2012)