Execute script based on change to Mysql Records count
<p>How do I execute a script based on a change to the total count of records in a mysql table. <code>div1</code> echoes the amount of records in a table just fine. Using the .load ajax request, the div is constantly refreshed every 0,5 second so it'll always know how many records there are almost real-time.</p>

<pre><code> &lt;div class="div1"&gt; 
            &lt;?php $row_cnt = mysqli_num_rows($result);   
            echo "table has $row_cnt records" ; ?&gt;                  
 &lt;/div&gt;

 &lt;script&gt;
    function refreshdiv(){
        $('.div1').load('backendform.php',function () {
             $(this).unwrap();
        });
    }
    refreshdiv();
    setInterval(function(){
        refreshdiv();
    }, 500);
&lt;/script&gt;
</code></pre>

<p>Here I'm trying to figure out how to call a JS function when the count has changed within the last minute (or second, doesn't matter). So if $row_cnt has for example changed from outputting 5 to 6, how do I trigger the execution for this statement? </p>

<pre><code>&lt;?php
//if record was added in last minute
if($row_cnt...)
echo '&lt;script type="text/javascript"&gt;',
     'notification();',
     '&lt;/script&gt;'
;?&gt;
&lt;script&gt;
</code></pre>

<p>I suppose what also could work is if I could tell if a record has been added to the Mysql table within the last few seconds. Each record has a timestamp. But I don't even know if this can be done because I found no similar questions on SO.</p>