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
Time getting updated automatically when updating other field
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
I believe, if you explicitly set the timestamp, it won't update.. sowrote: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.
Code: Select all
UPDATE `tbl1` SET `EntryTime` = `EntryTime`, `Viewed` = `Viewed` + 1 WHERE `id` = 'blah'