Solved

php pdo insert again if row columns are different

Posted on 2013-10-24
5
329 Views
Last Modified: 2013-11-11
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
Comment
Question by:rgb192
  • 3
  • 2
5 Comments
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39599315
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
 

Author Comment

by:rgb192
ID: 39599429
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
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39600048
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
 

Author Closing Comment

by:rgb192
ID: 39639665
This would insert into the needed first row every time.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39639804
Thanks for the points and thanks for using EE, ~Ray
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Ajax php search with multiple text fields generated by php 38 71
Combining Queries 7 28
How do I show metrics with PHP or Javascript 6 34
issue with DB import 1 19
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question