Hi I am trying to discover how to fix my query to return the correct result. Here is my query:
$selectShoeRatingQuery = "SELECT cast(round(AVG(rating)*2)/ 2 as decimal(10,1)) FROM rating WHERE shoe_id = '$_GET[id]'";
$shoeRating = mysql_query($selectShoeRatingQuery);
The query should return a number with one decimal place (3.5). It works fine when testing in PhpMyAdmin, however on my site it returns resource id #8.
The database connection all works fine.
解决方案
mysql_query returns a resource. You need to get a row from it:
$query = mysql_query($selectShoeRatingQuery);
$row = mysql_fetch_row($query);
$shoeRating = $row[0];
And, unless you have no choice - don't use the mysql_ set of extensions! They're deprecated, and PDO et al. are better. And your query is vulnerable.