Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6535955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:26:03+00:00 2026-05-25T10:26:03+00:00

In a chat room I have a bot that will collect information such as

  • 0

In a chat room I have a bot that will collect information such as when a person joins or leave and fill up a database where I would like to have statistics of how long people usually stay and which rooms, etc.

Not reflecting so much I’ve done the follow table:

CREATE TABLE IF NOT EXISTS `users_login_logs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `uid` int(11) NOT NULL,
  `username` varchar(16) NOT NULL,
  `room_id` int(11) NOT NULL DEFAULT '0',
  `action` tinyint(1) NOT NULL DEFAULT '0',
  `ip` int(10) unsigned NOT NULL DEFAULT '0',
  `ts_register` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

action is either 0 for entering the room and 1 to leaving.

After some running It doesnt seem that this layout is the best one for what I want, for example calculating when the user entered / left would be a bit confusing and could produce wrong results if for example for w/e reason the bot does not record or miss any data.

What could I do to make this layout more reliable for quering the users presence to retrieve the amount of hours, dayly, weekly and month the users are in the room X for example ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:26:04+00:00Added an answer on May 25, 2026 at 10:26 am

    I would create something along the lines of:

    id - primary key
    user_id - foreign key
    room_id - foreign key
    time_entered - timestamp
    time_left - timestamp
    (other fields as needed)
    

    On a user’s signin, create a new record with a NULL time_left, on a user’s signout, update the record and store the time_left. When your application starts, look for any records with a NULL time_left – that would signify the app crashed/missed some exits and needs to close them out (however you want to handle that).

    You could get a list of who was in the room by WHERE time_left IS NULL, and calculating how long a user was online is trivial.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a counter that counts the number of viewers in a chat room
I have an online chat room that uses jQuery/Ajax for requesting data from the
I have a social network that is wanting to implement a chat room for
I have a TextArea that shows the conversation from selected chat room. For valueCommit
is there any active irc chat room that have people to talk to?
I have a WCF chat service that accepts duplex tcp connections. A single duplex
I am working on a java program that is essentially a chat room. This
I have this code right now that sets the nick and room: io.sockets.on('connection', function(client){
For example. if I have a chat app that uses objects like: ChatRoom and
i'm writing a chat app with php/mysql i have 3 tables: user, room and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.