0

I have a MySQL table for guesses for matches , when any user make a guess the table take the current time-stamp of that guess. And when the match finished the table will update the match result field. My problem is that when the table update the result it updates the time-stamp also how I can stop that change to the time-stamp using MySQL or PHP? I just want to change the result field and my query does not include the time-stamp but even though it is being updated. My table contains :

match_id, timestamp, result, guess

That is my query:

 UPDATE guesses SET result = $kg_yok where match_id= $match_id AND guess = 11
Basel
  • 1,305
  • 7
  • 25
  • 34

5 Answers5

0

I don't know if I'm understanding you, but I think you should change your mysql table options for timestamp make it null or none. don't do current_timestamp

user2898514
  • 27
  • 1
  • 7
0

Declare the field where you want to store time and date as DATETIME as TIMESTAMP gets updated every time you update yout record whether you want it or not

DateTime vs Timestamp

Community
  • 1
  • 1
Artur
  • 7,038
  • 2
  • 25
  • 39
0

First of all i would rather suggest that you should change your column from timestamp to datetime and insert/update date every time manually using query. Defining coumn as datetime will give you more control in specifing time of particular timezone only

Still if you want to continue with timestamp you as read document

Nikhil
  • 99
  • 1
  • 9
0

Thanks guys but I think I Figure out the solution. I change my query to :

UPDATE guesses SET result = $kg_yok, timestamp=timestamp 
where match_id= $match_id AND guess = 11

This will take the same value of the time-stamp filed and reassign it to the new update, by that I can keep the value unchanged by reassign it again.

Basel
  • 1,305
  • 7
  • 25
  • 34
0

Although you found a solution, you might want to consider modifying the table slightly. You have a timestamp field to record when an action occurs, but if you want to know when the record was created, you need two fields:

created_at: TIMESTAMP DEFAULT CURRENT_TIMESTAMP

updated_at: TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

Alternatively, why not simply log all guesses

JBC
  • 112
  • 5