-6

I want to keep checking a mysql query for rows in the database the same way a chatroom constantly queries and loads new messages. In effect, checking and loading new messages as they are entered into the database.

Also, any tips on how to add a sound effect when new queries are retrieved? Many Thanks

Don
  • 863
  • 1
  • 8
  • 22
user1337603
  • 285
  • 2
  • 4
  • 9

3 Answers3

0

What you're looking for is a repeating, timed poll. You can do this with javascript's setTimeout() method.

As far as playing a sound, I can't help you there.

Matt
  • 6,993
  • 4
  • 29
  • 50
0

If whenever you want to an action to be performed when data is inserted into database, is to use Trigger.

http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html

But this action can only be another database action, meaning you cannot have your php script be notified about it.

So in your case, its best to run a cron job every 5 minutes or whatever time interval you prefer.

Try these links:

http://www.werockyourweb.com/cron-job-mysql

Ivin
  • 4,435
  • 8
  • 46
  • 65
0
var auto_refresh = setInterval(
function ()
{
    // call your php through ajax -- which inturn checks your db
    $.ajax({
      url: "script.php",
      type: "POST",
      data: {id : menuId},
      dataType: "json",
      success: function(){
        alert('success');
                    //if there is data to be populated, play sound and populate you div/textarea

      }       
    });
 }, 10000); // refresh every 10000 milliseconds

for the sound you can try this Cross-platform, cross-browser way to play sound using jQuery 1.4?, i have never tried but the answer has been accepted so should work. if it doesnot work you may also try this https://github.com/admsev/jquery-play-sound

Community
  • 1
  • 1
Vanamali
  • 291
  • 1
  • 6