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 8650199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:45:37+00:00 2026-06-12T13:45:37+00:00

Possible Duplicate: How to count online users on a website How do I take

  • 0

Possible Duplicate:
How to count online users on a website

How do I take off the users that have closed the browser or tab and place them back on when they come back to the page in my online user list? here is my code :

 $sql = "SELECT
user_id,
user_name,
user_class,
online
FROM
users
WHERE
online = 1
GROUP BY
 user_name ASC ";
$result = mysql_query($sql);
if(!$result)
{
echo 'There are currently no user online.' . mysql_error();
}
else
{
if(mysql_num_rows($result) == 0)
{
    echo 'There are currently no user online.';
}
else
{
    //display category data
    while($row = mysql_fetch_assoc($result))
    { $D= $row['online']; 
    if( ($D) !=1)
    {
    echo 'There are currently no user online.';
}
else
{ 
         echo'<a href="/index.php?area=profile&userid=' . $row['user_id'] .  '" ' . $row['user_class'] . '>' . $row['user_name'] . '</a>, ';}}}}?>
  • 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-06-12T13:45:38+00:00Added an answer on June 12, 2026 at 1:45 pm

    You wouldn’t use a flag in the DB like this.
    You should set a relational table that logs the last appearance of the user. Usually a margin of 5 minutes or so.

    Basically, every page load you log in a table user_id, datetime

    Then every page load where you care to know who is online you check that table where datetime is >= time – 5 minutes.

    The tutorial in the comments may be more useful if you have no idea what I mean, but in general the idea is this:

    Log when a user interacts with the site. This could be on page load, ajax request, etc, in a relational table. I suggest relational because it allows you to track all behavior and avoids updating the user table unnecessarily.

    INSERT INTO `site_activity` (`user_id`, `date_time`) VALUES ( $user_id, NOW() )
    // by the way, here we assume you're escaping $user_id
    

    Then on page load you query that table. You can either do it directly for a count, or join on the user table to report WHO is online. Below is a basic query to get results from the last 5 minutes.

    SELECT * FROM `site_activity` WHERE `date_time` >= DATE_SUB( NOW(), INTERVAL 5 MINUTE )
    

    This is just to give a basic idea of the structure. A use case scenario would require a lot more info on your needs, existing code, etc.

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

Sidebar

Related Questions

Possible Duplicate: mysql count into PHP variable I have the following query that returns
Possible Duplicate: Hibernate HQL: Get count of results without actually returning them I have
Possible Duplicate: Count(*) vs Count(1) If I have a table, 'id' is primary key,
Possible Duplicate: Count specific character occurances in string I have a delimeter in string
Possible Duplicate: NSNumber retain count issue Hello, I have the following code: NSNumber *number
Possible Duplicate: SQL Count records within a month using a unix timestamp I have
Possible Duplicate: How to get line count cheaply in Python? Good day. i have
Possible Duplicate: linq-to-sql group by with count and custom object model I have a
Possible Duplicate: String Functions how to count delimiter in string line I have a
Possible Duplicate: count date difference in hours using php and mysql I have a

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.