0

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

Austin M-S
  • 49
  • 5

1 Answers1

1

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");
Community
  • 1
  • 1
Ben Shoval
  • 1,732
  • 1
  • 15
  • 20
  • Where exactly do I place the location of the sound? I am going to put it under ../includes/notificationSound – Austin M-S Jul 21 '16 at 03:34
  • @AustinM-S If by "the sounds" you mean the success.wav file, you need to put it somewhere it can be accessed by your HTML code. I don't know your directory structure, but if you're going to use the code as I wrote it, the success.wav file should likely be in the folder with a name like public_html. – Ben Shoval Jul 21 '16 at 03:46
  • Why can it not be in just some folder? The page is already pulling from the includes section... can it not do it for audio? – Austin M-S Jul 21 '16 at 03:50
  • If your includes folder is accessible to your HTML, then it can be in there. Just try it and see if it works. – Ben Shoval Jul 21 '16 at 04:02
  • What do I replace with the location? – Austin M-S Jul 21 '16 at 05:22
  • @AustinM-S change src="success.wav" to src="/path/to/success.wav" – Ben Shoval Jul 21 '16 at 07:14
  • @Bob Shoval Do you mind assisting me with the trigger? It's quite overwhelming to me. – Austin M-S Jul 22 '16 at 00:24