I have a MySQL database that holds details on various video games and user accounts. A user is able to review a game and the score is put into a review table. I am trying to retrieve the average score for each game and have it displayed on a webpage. My SQL statement within PHP looks like this
$sqlOverall = "SELECT CAST(AVG('scoreOverall') AS DECIMAL('10,1'))
FROM 'ratings'
WHERE gameID = '$id'";
$scoreOverall = mysqli_query($conn, $sqlOverall);
But when I try to echo $scoreOverall it returns blank.
try this below query
$selquery="SELECT CAST(AVG(scoreOverall) AS DECIMAL(10,1)) FROM ratings WHERE gameID='$id'";
$result= mysqli_query($conn, $selquery);
SELECT CAST(AVG(scoreOverall) AS DECIMAL(10,1))
FROM ratings
WHERE gameID = '$id';
Try above code. Hope this will helps.
It works fine. Hope it is your helpful
$sqlOverall="SELECT CAST(AVG(scoreOverall) AS DECIMAL(10,1)) FROM ratings WHERE gameID=$id";
$scoreOverall = mysqli_query($conn, $sqlOverall);
foreach ($scoreOverall as $value) {
$scoreOverall = $value['CAST(AVG(queue_status) AS DECIMAL(10,1))'];
echo $scoreOverall;
}