mysql选择count count id#10

时间:2012-10-04 21:39:19

标签: sql select

当我运行以下代码时,echo返回资源ID#10而不是数字,在我的情况下6.感谢任何帮助!

$result = mysql_query("SELECT COUNT(`category_id`) FROM `products_has_product_category`
WHERE `category_id`=1");
        echo $result;

1 个答案:

答案 0 :(得分:0)

使用函数mysql_fetch_objectmysql_fetch_row将查询结果转换为数据

$result = mysql_query("SELECT COUNT(`category_id`) as count FROM `products_has_product_category`
WHERE `category_id`=1");

$row = mysql_fetch_object($result);
$count = $row->count;
echo $count;

请参阅mysql_fetch_object