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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:02:26+00:00 2026-06-04T10:02:26+00:00

I have the following function function availableChatRoom($topic_id){ $max_rooms = 2; $max_users = 2; $sqli

  • 0

I have the following function

function availableChatRoom($topic_id){
$max_rooms = 2;
$max_users = 2;

$sqli = "SELECT COUNT(DISTINCT room_num) AS numRooms FROM forum_chat WHERE topic_id = '$topic_id'";
$num_rooms = queryColumnVal($sqli, "numRooms");

$sqlii = "SELECT room_num, COUNT(user_id) AS numUsers FROM forum_chat 
          WHERE topic_id = '$topic_id' AND (status = 'online' AND status = 'offline') AND chat_msg = ''
          GROUP BY room_num
          HAVING numUsers < $max_users ORDER BY msg_date";

$num_rooms_with_spaces = mysqlNumRows($sqlii, "room_num");
queryColumnVal($sqlii, "room_num");

if($num_rooms == 0){
    return 1;
}
elseif($num_rooms <= $max_rooms){

    if($num_rooms_with_spaces == 0){
        return $num_rooms + 1;
    }
    else{
        return queryColumnVal($sqlii, "room_num");
    }
}
else{
    return "none";
}   

}

the idea is for the function to return a chat room number with space.
-Every time a user joins the room, a line with no msg is inserted with status online
-Every time a user leaves the room a line with no msg is inserted with status offline
I am now trying to write a function which checks if there are any spare rooms for each topic
The idea is to select the room_num where the number of users who have logged in but not logged out is less than the maximum chatter per room.
Can someone help me with my $sqlii.

Thanks

  • 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-04T10:02:28+00:00Added an answer on June 4, 2026 at 10:02 am

    There are several errors in your query:

    • (status = 'online' AND status = 'offline')

    This asserts that your query wil return no now at all. Use: (status = 'online' OR status = 'offline') or the equivalent (status IN ('online', 'offline'))

    • COUNT(user_id)

    This does not count the difference of online minus offline users. Correct the logic.

    • ORDER BY msg_date

    In GROUP BY queries, it’s not good to use non-aggregate column, at the HAVING, SELECT or ORDER BY clauses, despite that MySQL allows it. Unless that column depends on the grouping expression. Since msg_date obviously does not depend on room_num, you should replace that with an aggregate function:

    ORDER BY MAX(msg_date) or ORDER BY MIN(msg_date)


    $sqlii = "
       SELECT room_num, 
              COUNT(CASE WHEN status = 'online' THEN 1 END) 
                - COUNT(CASE WHEN status = 'offline' THEN 1 END) 
              AS numUsers 
       FROM forum_chat 
       WHERE topic_id = '$topic_id' 
         AND status IN ('online', 'offline')
         AND chat_msg = ''
       GROUP BY room_num
       HAVING COUNT(CASE WHEN status = 'online' THEN 1 END) 
              - COUNT(CASE WHEN status = 'offline' THEN 1 END) 
              < $max_users 
       ORDER BY MAX(msg_date)
         ";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following function inside my module. Function Colorize(myValue) ActiveCell.Select Selection.Font.Bold = True
Suppose we have following function in PHP: public function testSomething() { $name = perform_sql_query("SELECT
I have the following function that is pulling data from a database. The ajax
I have following function which is called continuously from run() of a Thread which
I have the following function: - (NSString *)urlEncodedValue { NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(
I have the following function void initBoard(int * board[BOARD_ROWS][BOARD_COLS]){ int z = 0; for(
I Have the following function. function ChangeDasPanel(controllerPath, postParams) { $.post(controllerPath, postParams, function(returnValue) { $('#DasSpace').hide(slide,
I have the following function sending an email twice (and I believe running if($result)
I have the following function that deletes the LaTeX command surrounding the current cursor
I have the following function: >>> def rule(x): ... rule = bin(x)[2:].zfill(8) ... rule

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.