I want to be able to update a row with the highest ID.
The problem is: I can’t find any elegant solution to do this.
This is my best attempt so far:
$highestId = mysql_result(mysql_query('SELECT MAX(id) FROM stats'),0);
mysql_query("UPDATE stats SET views = views +1 WHERE id = $highestId");
Maybe there there is a better approach than I am thinking of.
- I am tracking the amount of views, every day
- I want it to auto-increment the last (highest id) day
- In the evening I’m running a cronjob that creates a new day.
Any suggestion on how to tackle this problem are welcome, even if it is a whole different approach.
Table stats => id | views
Yes: