We have a postgresql query inside a javascript function which is as follows:
function valor(){
<?php
$con_string = "host='ip' port=numero dbname='banco' user='usuario' password='***'";
$conn = pg_connect($con_string);
$query="SELECT tubeteira from velocidadereal";
$output=pg_query($conn,$query);
$retorna = pg_fetch_array($output);
$valor = $retorna["tubeteira"];
?>
return <?php echo $valor ?>;
}
setInterval(valor,1000);
But although it updates every 1 second the variable php is not updating in the function, so when changing the value in the database of the column where we are performing the select it does not return the new value unless we refresh the page.
How can I get it to update automatically?
It's important to note that the query is feeding a chart.