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

  • Home
  • SEARCH
  • 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 8913417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:27:33+00:00 2026-06-15T04:27:33+00:00

When I do not use if condition($last_msg_id_db>$last_msg_id) in load.php file then jquery function works

  • 0

When I do not use if condition($last_msg_id_db>$last_msg_id) in load.php file then jquery function works allright and keep checking the data after each half second.

However If i use, if condition , jquery function works only first time but after first time running, it did not work and stops working.

I think ,I am not placing the if condition in load.php at right place.Plz help Or suggest any alternative approach.

php file(Load.php) is here

 $last_msg_id=$_POST['last_msg_id'];

$sql=mysqli_query($db3->connection,"SELECT * FROM chat_com ORDER by id ASC");

$sql_m=mysqli_query($db3->connection,"SELECT max(id) as maxid  FROM chat_com");
$row_m=mysqli_fetch_array($sql_m);
$last_msg_id_db=$row_m['maxid'];
if($last_msg_id_db>$last_msg_id){

    while($row=mysqli_fetch_array($sql)){

        $textt=$row['mesg'];
        $textt2="$textt<br>";

        $response=array();

        $response['msg']=$textt2;
        $response['last_msg_id_db']=$last_msg_id_db;
        $final_response[]=$response;
    }
}
echo json_encode($final_response);

Jquery function is here.

var last_msg_id = 1;
function chat_com_one(id, name) {
  $('#chatcom').show('fast');
  (function chatcom_load_one(id, name) {
    alert(last_msg_id);
    $.post('load.php', {option:'chatcom_load_one', last_msg_id:last_msg_id},     function(data) {
        var json = eval('(' + data + ')');
        $.each(json, function(i, row) {
            $("#chatcom #commid #commidwin").append(row['msg']);
            last_msg_id = row['last_msg_id_db'];
        });
        setTimeout(chatcom_load_one(id, name), 500);
    });
}(id, name));
$('#chatcom_send').click(function() {
    $.post('send.php', { option:'chat_com_send_one', text:$('#chatcom_text').val(), tocom:id}, function(data) {
        document.getElementById('chatcom_text').value = '';
    });
});
}
  • 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-15T04:27:34+00:00Added an answer on June 15, 2026 at 4:27 am

    It may have not worked because $final_response may not have any data after second time ajax request and the condition could have failed to set values to $final_response.

    You may have to initialize $final_response in top of the if condition,

    $final_response = array();
    if($last_msg_id_db>$last_msg_id){
       ...
       ...
    }
    echo json_encode($final_response);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use Case When with AND condition and it is not calculating
I can not use content://sms? Works on all Android devices? I'm using SmsManager but
Because codenameone can not use external libraries (HttpConnection) then I have to use the
I do not use that many functions but when I do I tend to
I do not use C++ much (I try to stick to the easier stuff
I do not use HibernateTemplate, but work with getCurrentSession() in my DAO. I would
if I do not use a mock framework to create a mock, but write
What tasks should one not use HBase for? My understanding is that HBase and
I have a SMTP account that does not use encrypted connection. I can use
i have been told to use 'when' statement to make multiplexer but not use

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.