I create a CGI to administrate news items, I've created the database on MySQL. Each of the news items has a timestamp field to know the date and time each of the news where submited.
When a user sees a news item I run a function that adds the number of views that item has:
my $id = shift;
my $current_views = shift;
my $new_views = $current_views + 1;
$dbh = BaboonDB->connect();
$sth = $dbh->prepare('UPDATE news SET views=? WHERE id=?') or die("
+Couldn't prepare statement: " . $dbh->errstr);
$sth->execute($new_views,$id) or die("Couldn't execute statement: "
+ . $sth->errstr);
The code runs correctly and adds the views without a problem. The thing is that when I update the views field, the timestamp field is also updated.
What I would like to know if there is a way to avoid this?