This is my table structure: dailyAverages(epochDay, totalScore, totalPlays, averageScore), average score is a calculated column = totalScore/totalPlays.
I have it being updated correctly by a PHP script, but when I try to retrieve a value to display on my webpage I can't seem to get anything. Here is the PHP (with credentials removed):
<?php
$epoch = intval($_GET['e']);
$con = mysqli_connect($servername, $user, $pass);
if(!$con){
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,$dbname);
$sql = "select * from dailyAverage where epochDay = ".$epoch;
$sqlRet = mysqli_query($con, $sql);
echo $sqlRet['averageScore'];
if(!is_null($sqlret['averageScore'])){
echo $sqlRet['averageScore'];
}else{
echo 0;
}
?>
and here is where I make the call in my JS
function getGlobalAverage(){
console.log("Creating GET XMLHttpReq");
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if(this.readyState == 4 && this.status == 200) {
console.log("GET is Ready...")
globalAverage = this.responseText;
console.log(globalAverage);
document.getElementById("averageSpan").innerHTML = globalAverage;
}
}
console.log("Opening GET...");
xmlhttp.open("GET","../getGlobalAverage.php?e="+epochDays,true);
console.log("Sending GET...");
xmlhttp.send();
}
I have tried a bunch of different fixes but I haven't been able to get it to actually retrieve the info. Based on what I currently have in the database it should be pulling out a simple 7, but alas.