I have 4 rows in my SQL table. id, tokenid, score and time.
If a player is playing the game for the first time, I can save it to the database. If a player replays and collects more points than when they first played, I can save that to the database as well. What I want to do and what I cannot do is; adding the player's time in the game with the most points to the database. When I try to do this, it saves it to the database even if the player has scored less points than the previous game. When I try to do this it updates the time value even if the player collects less points than the previous game.
This is how it works now:
- First Game player scores 15 points at 19:00:00 (Database; score: 15, time: 19:00:00)
- Second Game player scores 13 points at 19:02:00 (Database; score: 15, time: 19:02:00)
- Third Game player scores 17 points at 19:03:00 (Database; score: 17, time: 19:03:00)
This is what I want:
- First Game player scores 15 points at 19:00:00 (Database; score: 15, time: 19:00:00)
- Second Game player scores 13 points at 19:02:00 (Database; score: 15, time: 19:00:00)
- Third Game player scores 17 points at 19:03:00 (Database; score: 17, time: 19:03:00)
$tokenid = $_POST["tokenid1"];
$score = $_POST["score1"];
$time = date("H:i:s");
$records= "INSERT INTO scoreboard (tokenid, score, time)values('".$tokenid."', '".$score."', '".$time."') ON DUPLICATE KEY UPDATE score= GREATEST(score, VALUES(score))";
I made some attempts for the time variable after the score variable, but I was not successful.