0

How to count number of rows from database after every 2 seconds without refreshing page

" id sender receiver message " these are database fields

I want to count and display number of message received after every 2 seconds, like

OUTPUT:- " Messages (1) "

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Nichito
0

Try AJAX. It will not refresh the webpage, though it will send a separate request to the server asking for the information you need.

function showRecords(str)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("messagesDiv").innerHTML="Messages (" . xmlhttp.responseText . ")";
    }
  }
xmlhttp.open("GET","getrecords.php",true);
xmlhttp.send();
}

so getrecords.php contains the php code that queries the database for new records, and you call the javascript unction every 2 seconds. document.getElementById["messagesDiv"] refers to an html container with that id, which reflects the quantity of records in the database.

Edited by Nichito: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.