How to update MySQL results automatically with JavaScript? [closed]

0

How do I automatically update MySQL queries with JavaScript?

I was looking at the site and found something that helped me just put it on my site and when I went to see the server processes the second file query.php was opening more than 150 processes ( leaving the server super slow ) is there any more practical way to solve my problem?

<script type="text/javascript">
function doRefresh(){
    $("#contagem").load("consulta.php");
}
$(function() {
    setInterval(doRefresh, 100);
});
</script>

Query.php file

<?php
require_once "config.php";

$data = mysql_fetch_array(mysql_query("SELECT * FROM teste WHERE ativo='1' ORDER BY RAND() LIMIT 1;")); 
$t = time() - $data['tempo'];   
echo "<font color='green'><h1>Tempo: $t</h1></font>";
mysql_close($mysql); ?>
    
asked by anonymous 21.11.2017 / 23:24

1 answer

1

Legal if possible was to change to setInterval(doRefresh, 1000); And make sure your server has automatic connection closure if you do not have to do it via code.

    
22.11.2017 / 10:21