sederhananya seperti ini:
pertama buat file cek.php untuk cek data baru
<?php
$lastCount = $_GET['last'];
$query = mysql_query("select count(*) from nama_table");
$rs = mysql_fetch_array($query);
$newData = $rs[0] > $lastCount;
echo json_encode(array('newData' => $newData));
di file yang akan diimplement, misal file index.php
<!-- tambah jquery --->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
function PlaySound(soundObj) {
var sound = document.getElementById(soundObj);
sound.Play();
}
<?php
$query = mysql_query("select count(*) from nama_table");
$rs = mysql_fetch_array($query);
echo 'var lastCount = '.$rs[0].';';
?>
function checkData(){
$.ajax({
url:'cek.php?last='+lastCount,
dataType:'json',
success:function(resp){
if(resp.newData){
PlaySound('sound1');
}
},
complete:function(){
setTimeout("checkData()",1000);
}
});
}
</script>
<embed src="success.wav" autostart="false" width="0" height="0" id="sound1" enablejavascript="true"/>
beberapa tutorial AJAX
http://www.myphptutorials.com/categories/2/tutorial-ajax