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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:53:38+00:00 2026-06-14T08:53:38+00:00

Hi since 3 hour I am trying to make this work but not getting

  • 0

Hi since 3 hour I am trying to make this work but not getting the result as I want. I want to display user list with online and offline status.

Here is the table

and here what I tried to get status result.

$loggedtime = time() - 300; // 5 minutes

$query = 'SELECT userid, handle FROM ^users WHERE loggedin = '.$loggedtime.' ORDER BY userid ASC';

// below are scripts function qa_ pleses refer this http://www.question2answer.org/functions.php

$result = qa_db_query_sub($query);  
$users = qa_db_read_all_assoc($result); 

$row = mysql_fetch_array($result);

if($row['userid'] > $loggedtime){
    echo $row['handle'].' is online';
} else {
    echo $row['handle'].' is offline';
}

NOT THIS TOO

foreach($users as $user){
    if($user['userid'] > $loggedtime){
        echo $user['handle']. ' is online';
    } else {
        echo $row['handle'].' is offline';
    }
}

None of above code working. I am new to MYSQL and PHP just know basic so please help me to solve this.

EDIT:
I have tried now this but not working

foreach($users as $user){
                if($user['loggedin'] > $loggedtime){
                    echo $user['handle']. ' is online';
                } else {
                    echo $row['handle'].' is offline';
                }
            }

EDIT 2

$query = "SELECT
    userid, handle, 
    CASE
        WHEN TIMESTAMPDIFF(SECOND, loggedin, NOW()) < 300
            THEN 'Online'
        ELSE 'Offline'
    END AS 'status'
FROM ^users
ORDER BY userid";

$result = qa_db_query_sub($query); 

while($user = mysql_fetch_array($result)){
    echo $user['handle'] . '<BR/>';
}

NEW APPROACH

Please check this for new approach User online offline status – offline status issue

  • 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-14T08:53:39+00:00Added an answer on June 14, 2026 at 8:53 am

    Since you fixed the user id comparison, let’s address the next issue..

    You’re trying to compare a string DATE versus a unix timestamp. Let’s make them the same type and compare:

    foreach($users as $user)
    {
      $user_time = strtotime($user['loggedin']);
      if($user_time > $loggedtime)
      {
        echo $user['handle']. ' is online';
      } else {
        echo $row['handle'].' is offline';
      }
    }
    

    Overall not the best way to approach this problem, but it might get this working for you. The database solution above is probably best.

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

Sidebar

Related Questions

Ok, I'm slowly getting a grasp on this, but I need some more help.
I feel like a moron asking this, but since I'm a new to developing,
I'm new to javascript and probably trying to do something stupid since an hour
Im trying to convert a timestamp in seconds since 01/01/1970 with an hour timezone
So I am trying to make a Function which returns a list of data,
I'm trying to make a subclass of NSCalendar, but without much luck. I've tried
I'm trying to make a time field in my form optional. I'm doing this:
So I'm trying to make a Chrome extension that takes in user input in
I know that there are similar threads but after spending an hour trying to
since memcpy should be highly optimized nowadays, does it still make sense to optimize

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.