本文介绍了MySQL查询返回资源ID#8而不是期望值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试发现如何修正查询以返回正确的结果.这是我的查询:
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);
查询应返回一个小数点后一位数字(3.5).在PhpMyAdmin中进行测试时,它工作正常,但是在我的网站上,它返回resource id #8
.
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
.
数据库连接一切正常.
推荐答案
mysql_query
返回资源.您需要从中获得一行:
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];
而且,除非您别无选择-请勿使用mysql_
套扩展名!他们已被弃用,PDO等人.更好.而且您的查询很容易受到攻击.
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.
这篇关于MySQL查询返回资源ID#8而不是期望值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!