• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

php pdo insert again if row columns are different

Some sort of id,
Timestamp
First name,
Last name,
Email
Weight

User may change any column
Want timestamp recorded if any column altered





User may change first
0
rgb192
Asked:
rgb192
  • 3
  • 2
1 Solution
 
Ray PaseurCommented:
If any column is altered the TIMESTAMP column will be altered.  If there are no changes to the row, the TIMESTAMP column will not be altered. That is expected MySQL behavior.

It follows that if you create an UPDATE query that tries to UPDATE a row with column "weight" = 150 and the row already had column "weight" = 150, no update will occur.  I have never tested this, but I expect that you could experiment with a DATETIME column to cause an update to occur every time.  Just a thought, ~Ray
0
 
rgb192Author Commented:
I literally want to 'insert again' if results are different

for example if user changes their weight (int) or email (varchar)  then they get another row.


This is not an update.
0
 
Ray PaseurCommented:
In that case I would just INSERT the new row every time.  When you SELECT you can ORDER BY the timestamp column DESC with LIMIT 1 and you will always get the latest values.
0
 
rgb192Author Commented:
This would insert into the needed first row every time.
0
 
Ray PaseurCommented:
Thanks for the points and thanks for using EE, ~Ray
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now