What I'm trying to accomplish is this - update the table with certain values only IF the high-score is better than the current one.
Got table with columns userId, highScore, something, dateLastPlayed
User with userId of 1 has beaten his own score, and in that case I want to update all the fields in the row. If he has not beaten his own high-score, I just want to update the dateLastPlayed field.
This is how I insert stuff so far
INSERT INTO table VALUES ('$userId', '$highScore', '$something', '$dateLastPlayed') ON DUPLICATE KEY UPDATE highScore='$highScore', something='$something', dateLastPlayed='$dateLastPlayed'
Note that userId has unique key.
This works fine but this updates highScore, something and dateLastPlayed fields every time. I want to update fields highScore and something only IF the variable $highScore is greater than what is current set in the database.
I have read the MySQL docs but I do not quite get it. How can I accomplish this? Note that I could do this using multiple queries and fetching data and then make more queries using that data, but I feel that is simply not the way to go and that it would take literally seconds for you guys to come up with a brilliant way to tackle the problem.
Many thanks!