I'm attempting to return the value of a database integer called "followers_count", so that the user needs not refresh the webpage to see the change. However, my code does not work. Any help is appreciated.
What I have for the script:
<script type="text/javascript">
$(document).ready(function() {
$.getJSON('change.php', function(data) {
$('#follow_count').html(data.followers_count);
});
});
</script>
In change.php: (Edited per comments, but getting error "followers_count=null")
<?php
require_once 'dbconfig.php';
require_once 'class.channel.php';
$user_change = new USER();
$userID = ( isset( $_GET['id']) && !empty( $_GET['id'] ) ) ? trim($_GET['id']) : '' ;
$stmt = $user_change->runQuery("SELECT * FROM tbl_users WHERE userID=:uid");
$stmt->execute(array(":uid"=>$userID));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$currFollows = $row['followers_count'];
$seqFollows = $user_change->runQuery( "SELECT currval('followers_count')" );
if ($seqFollows == $currFollows){
exit(0);
}
//$query = $user_change->runQuery($seqFollows);
while($row = mysqli_fetch_array($seqFollows))
{
$follows = $row['followers_count'];
}
header('Content-type: application/json');
$array = array('followers_count'=>$follows);
echo json_encode($array);
?>
The HTML:
<div>
Channel Adds: <div id="follow_count"></div>
</div>