0

I am currently using this code for updating ever 2 seconds, how ever I don't know how I could make it update via change or update in the database table.

   <script>
function loadlink(){
    $('#links').load('elements/feed-load.php',function () {
         $(this).unwrap();
    });
}

loadlink(); // This will run on page load
setInterval(function(){
    loadlink() // this will run after every 5 seconds
},2000);
</script>
<div id="links">

</div>
Casper Round
  • 7
  • 1
  • 7

2 Answers2

1

Use live connection / web-sockets, for MySQL create a stored procedure + trigger with a sys_eval() call. Yes, it is not easy. Yes, it is possible.

Some details can be also found here: Invoking a PHP script from a MySQL trigger

Community
  • 1
  • 1
Axalix
  • 2,831
  • 1
  • 20
  • 37
-2

What you are talking comes under socket programming concept in php, you cannot do this in normal php coding.

link http://php.net/manual/en/intro.sockets.php

I hope this helps you.

Sourabh Kumar Sharma
  • 2,864
  • 3
  • 25
  • 33
  • you can do it also without using socket as he is doing. This tecnique is known as longpolling and with can be valid. Sockets are anyway more efficient and less resources consumning – Lelio Faieta May 16 '15 at 17:20
  • @LelioFaieta what he asked in his question was that he wants a trigger to be fired as soon as some change occurs in database, please read the question again. What your saying is totally different and what the person in his question is totally different, also read his comments below the question. – Sourabh Kumar Sharma May 16 '15 at 17:25
  • I use to do longpolling to do the same as he wants. It is just a matter of timing. sockets are more efficient but since he is using ajax and php he can get what he asks. It was already possible before using sockets. – Lelio Faieta May 16 '15 at 17:32