Hello,
I want to know roughly how long do registered users browse my website,
Every login is registered.
I want to update logout time every page load / reload (and logout)
Here is a screenshot of the table
MAX() is an aggerate function and should/must (depending on your database server’s strict mode setting) be used with a GROUP BY term in a SELECT (data retrieval) query.
You can use a SELCT sub-query to do this -
UPDATE logs
SET logout_t = NOW()
WHERE l_id = (SELECT MAX(l_id) FROM logs WHERE user_id = 30 GROUP BY l_id)
If you only want to do this for a logout_t value that hasn’t already been set, you would add AND logout_t IS NULL to the main query’s WHERE clause.