I need an alert sound to be played after a query on the bank ...
Logical example:
NUM_LINHAS = NUMBER OF TABLE LINES
SE (NUM_LINHAS > 0) {
play ();
}
My javaScript function that plays sound:
<audio id="audio">
<source src="alert.mp3" type="audio/mp3" />
</audio>
<script type="text/javascript">
audio = document.getElementById('audio');
function play(){
audio.play();
}
</script>
The "play ()" function is working because I created a button to test and the sound is played through onclick ()
<input type="button" value="test sound" onclick="play()";>
OK. Now I need this alert sound to be played after my query in the bank, which will have a condition.
Follow the code:
<?php
//seleciona o numero de linhas da tabela
$consulta = $conexao->query("SELECT COUNT(*) FROM toyota_base where statuz='NOVO'");
//atribui a variavel $num_rows o numero de linhas
$num_rows = $consulta->fetchColumn();
//verifica se o numero de linhas é maior que 0 (zero)
if($num_rows > 0){
//toca o som de alerta
echo "<script> play();</script>";
}
?>
I do not know why the sound is not played anymore ... I need help with it. I did a test with an "alert ()" instead of my "play ()" function and the alert works correctly, but the sound does not play ...