It's quite easy to realize, all you need is to create another two fields in table with users: online (tinyint) and last_online (timestamp).
Each time (or each second time) user enters on the page you update the last_online to now() and set online to 1, like that:
UPDATE users SET last_online = NOW(), online = 1 WHERE id = $user_id
And execute another SQL statement to put offline users who are not online:
UPDATE users SET online = 0 WHERE online = 1 AND last_online < NOW() - 120
Where 120 is amount of seconds you want to put users in offline mode.
Then you can select users by online field. However I don't understand where do you want to display this data. Reply please.
users can see which user is online or offline
Do you want it display in bottom of main page on forum, or you have some kind of popup with info about user, or you want to display data on user's page or even in the topic section?