I am trying to make a Charity counter using jquery, php and mysql. I am trying to grab new values from mysql using php every 5 seconds without updating the page using 'window.setInterval()', but my problem is that it isnt grabbing new values but it keeps using the values it got at the start. so here' s the code, i hope some is able to help :).
window.setInterval(function(){
var needed = <?php echo neededGetFirst(); ?>;
var got = <?php echo gotGetFirst(); ?>;
console.log('needed: ' + needed);
console.log('got: ' + got);
var gaugeHeight = 223;
var gaugeBottom = 318;
var percent = (100 / needed) * got;
var heightOffset = (gaugeHeight / 100) * percent;
var bottomOffset = gaugeBottom - (gaugeHeight - heightOffset);
$('#gauge').animate({
height: heightOffset + 'px',
bottom: bottomOffset + 'px'
}, 1000);
for (var i = 2, limit = 7; i < limit; i++) {
var value = (needed / 5) * (i - 1);
$('#stamp' + i).text(value);
};
}, 5000);
EDIT
Is it possible to return the value from a file with some type of GET/RUN? by putting the php/mysql database functions in an file and use a return for the values.'
EDIT 2
The php code used in the file:
<?php
$pdo = new PDO('mysql:host=127.0.0.1;dbname=thermometer', 'root', '');
$sql = 'SELECT `got`.`value` AS got, `needed`.`value` AS needed FROM `needed`, `got`';
$statement = $pdo->prepare($sql);
$statement->execute();
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
$json = json_encode($result );
echo($json);
?>