Austin M-S
Austin M-S

Reputation: 49

How do I refresh a table and make an alert sound when a table row is inserted?

Basically I have a different script adding rows via MYSQL when it is called. Example: (I insert data into a table, and it inserts it into the database.)

On a separate page, I have the table displayed. I would like for the table to refresh every ten seconds. Each entry has an ID (+1 from the last entry). Whenever a call is inserted into the database, I want a alert sound to come up as well and make sure the table is refreshed.

I think the way I would check for a new entry is by checking if there is a +1 from the last entry, because rows are actively being removed.

Here's what I have for the page displaying the table: http://pastebin.com/NAVzUpfF

This is the included table: http://pastebin.com/YJBvY2ed

This is where the information is inserted: http://pastebin.com/V2qeTcwp

Upvotes: 0

Views: 916

Answers (1)

Ben Shoval
Ben Shoval

Reputation: 1750

Since you are using a MySQL database, you have two options for updating the "table" you mentioned in the second paragraph:

  1. Create a trigger (http://dev.mysql.com/doc/refman/5.7/en/faqs-triggers.html#qandaitem-22-5-1-10) and write a UDF (user defined function) to activate external code.
  2. Poll the database every 10 seconds.

Assuming your front end (the "separate page" you mentioned) is some combination of HTML and Javascript, you'll need to embed a short WAV file in the HTML, and then play that via code since there is no way to make a browser page beep directly.

Here is an example (taken from How do I make Javascript beep?):

<script>
function PlaySound(soundObj) {
  var sound = document.getElementById(soundObj);
  sound.Play();
}
</script>

<embed src="success.wav" autostart="false" width="0" height="0" id="sound1"
enablejavascript="true">

You would then call it from JavaScript code as such:

PlaySound("sound1");

Upvotes: 1

Related Questions