Page 1 of 1

Time getting updated automatically when updating other field

Posted: Sun Jul 25, 2004 11:32 am
by anjanesh
I have some fields in table tbl1. 2 of them are :
EntryTime: timestamp(14)
Viewed: integer

// mysql_query and all that........
$Viewed=$row['Viewed']+1;
When a person clicks on a particular item, the no: of views increases by one so I did : mysql_query("UPDATE tbl1 SET Viewed=$Viewed")
The EntryTime value exists when entering a new item and it automatically sets it to NOW().
Now, when I do this update for no: of views the EntryTime also gets updated to the current time (the time when the update takes place). I don't want that happening. I tried setting EntryTime to NULL and NOT NULL as default but still both ways a new entrytime gets updated when I'm updating some other field.
How do I rectify this ?
Thanks

Posted: Sun Jul 25, 2004 11:59 am
by feyd
wrote:Automatic updating of the first TIMESTAMP column in a table occurs under any of the following conditions:
  • You explicitly set the column to NULL.
  • The column is not specified explicitly in an INSERT or LOAD DATA INFILE statement.
  • The column is not specified explicitly in an UPDATE statement and some other column changes value. An UPDATE that sets a column to the value it already has does not cause the TIMESTAMP column to be updated; if you set a column to its current value, MySQL ignores the update for efficiency.
I believe, if you explicitly set the timestamp, it won't update.. so

Code: Select all

UPDATE `tbl1` SET `EntryTime` = `EntryTime`, `Viewed` = `Viewed` + 1 WHERE `id` = 'blah'