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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:28:08+00:00 2026-05-31T02:28:08+00:00

all. I have built a simple jQuery/PHP chat program that works rather well. However,

  • 0

all. I have built a simple jQuery/PHP chat program that works rather well. However, I’d like to add a feature like channels or rooms. Ideally, I’d like to use tabs at the top of the chat to manage which room the user is in (there are only going to be 2). I thought this would be a simple task, and I have seen something similar done before, but I keep getting the uncaught exception error when the tabs are clicked, and the source doesn’t load correctly. i’ll post the code for the whole chat system, because I have a feeling the issue might lie therein.

the jquery

page = {
    getChat: function() {
        $.ajax({
            url: 'game_src.php',
            data: 'mode=getChat',
            dataType: 'html',
            cache: false,
            success: function(res){
                $("#chatbox").html(res);
            }
        });
    }
};

$("#submitmsg").click(function(){
    var clientmsg = $("#usermsg").val();
    $.ajax({
        url : 'game_src.php',
        data: 'mode=chatSubmit&msg=' + encodeURIComponent(clientmsg)
    });
    $("#usermsg").attr("value", "");
    return false;
});

setInterval(page.getChat, 4000);

$("#chatChannel").tabs({
    cookie: { expires: 1 },
});

the chat body

<?php
if($user->data['user_id'] == ANONYMOUS)
{

}
else
{
    ?>
    <div id="chatChannel">
        <ul>
            <li><a href="#global">Global</a></li>
            <li><a href="#alli">Alliance</a></li>
        </ul>
    </div>
    <form name="message" action="">  
        <input name="usermsg" type="text" id="usermsg" size="25" />  
        <input name="submitmsg" type="submit" id="submitmsg" value="Send" />  
    </form>
    <br />
    <?php
}
?>
<div id="chatbox" style="border:1px solid black;background-color: rgba(255,255,255,0.3);height:400px;overflow:auto;">
    <div id="global">
    <?php
    $chatMsgs = array();
    $limit = time()-86400;

    $sql = 'SELECT COUNT(chat_id) as count FROM '.CHAT_TABLE.' WHERE chat_channel = 0 AND chat_time > '.$limit;
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    $count = $row['count'];

    if($count > 0)
    {
        $sql = 'SELECT * FROM '.CHAT_TABLE.' WHERE chat_channel = 0 AND chat_time > '.$limit.' ORDER BY chat_time DESC';
        $result = $db->sql_query($sql);
        while($row = $db->sql_fetchrow($result))
        {
            $chatMsgs[] = array(
                'chat_time' => $row['chat_time'],
                'chat_msg' => $row['chat_msg'],
                'chat_user' => $row['chat_user'],
                'chat_channel' => $row['chat_channel']
            );
        }

        foreach($chatMsgs as $msg)
        {
            $sql = 'SELECT username FROM '.USERS_TABLE.' WHERE user_id = '.$msg['chat_user'];
            $result = $db->sql_query($sql);
            $row = $db->sql_fetchrow($result);
            $username = $row['username'];

            echo '<div class="chatMsg" style="border-bottom:1px solid black;">';
            echo '<div class="chatUsr">'.$username.' says:</div>';
            echo '<div class="chatUsrMsg" style="float:left;">'.$msg['chat_msg'].'</div>';
            echo '<div class="chatMsgTime" style="float:right;">'.date("g:i a", $msg['chat_time']).'</div>';
            echo '</div>';
            echo '<br />';
            echo '<hr />';
        }
    }
    else
    {
        echo '<div class="chatMsg">Nothing is heard but the sound of crickets...</div>';
    }
    ?>
    </div>
    <div id="alli">
    <?php
    $chatMsgs = array();
    $limit = time()-86400;

    $sql = 'SELECT COUNT(chat_id) as count FROM '.CHAT_TABLE.' WHERE chat_channel = 1 AND chat_time > '.$limit;
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    $count = $row['count'];

    if($count > 0)
    {
        $sql = 'SELECT * FROM '.CHAT_TABLE.' WHERE chat_channel = 1 AND chat_time > '.$limit.' ORDER BY chat_time DESC';
        $result = $db->sql_query($sql);
        while($row = $db->sql_fetchrow($result))
        {
            $chatMsgs[] = array(
                'chat_time' => $row['chat_time'],
                'chat_msg' => $row['chat_msg'],
                'chat_user' => $row['chat_user'],
                'chat_channel' => $row['chat_channel']
            );
        }

        foreach($chatMsgs as $msg)
        {
            $sql = 'SELECT username FROM '.USERS_TABLE.' WHERE user_id = '.$msg['chat_user'];
            $result = $db->sql_query($sql);
            $row = $db->sql_fetchrow($result);
            $username = $row['username'];

            echo '<div class="chatMsg" style="border-bottom:1px solid black;">';
            echo '<div class="chatUsr">'.$username.' says:</div>';
            echo '<div class="chatUsrMsg" style="float:left;">'.$msg['chat_msg'].'</div>';
            echo '<div class="chatMsgTime" style="float:right;">'.date("g:i a", $msg['chat_time']).'</div>';
            echo '</div>';
            echo '<br />';
            echo '<hr />';
                    }
    }
    else
    {
        echo '<div class="chatMsg">Nothing is heard but the sound of crickets...</div>';
    }
    ?>
    </div>
</div>

I’m going to add a parameter to the getChat jquery function to switch back and forth, but with what i have, i’m stuck. Can anyone point me in the right direction?

  • 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-31T02:28:09+00:00Added an answer on May 31, 2026 at 2:28 am

    The JQuery UI tabs plugin expects the content divs to be in the same container as the ul of links.

    In your case, it expects the content divs to be in the div id="chatChannel" right under the ul, but they aren’t there.

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

Sidebar

Related Questions

All, I have a PHP Web application built using Zend Framework and MVC with
I have this simple script that catches all mouse clicks, unless you click on
We have a J2EE app built on Struts2+spring+iBatis; not all DAO's use iBatis...some code
I have made a build system for my web application that's rewriting all resource
I have a bunch of ant projects that build plug-ins that all conform to
We have an existing web app built with jQuery Mobile. Our goal is to
I have a site built with simple templates; header.tpl, navigation.tpl, body_home.tpl, body_about.tpl, body_anotherpage.tpl, etc.
I'm learning to develop apps using Qt Creator. I have built a simple app
I have built a very simple CakePHP website using the Auth component and have
As you most likely already know, it's simple in JQuery to select all elements

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.