For every page where they're logged in, have a logincheck include, and in that, iff they're logged in have a query something like
UPDATE loggedusers SET timestamp = NOW() where userid = $_SESSION[userid]
Or if you're using unix timestamps for your log times (I always use them as I hate sql's in built tripe)
UPDATE loggedusers SET timestamp = UNIX_TIMESTAMP() where userid = $_SESSION[userid]