mysql查询只返回id,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);

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值