php-如何在echo中显示sql sum结果

php-如何在echo中显示sql sum结果,php,mysql,sql,Php,Mysql,Sql,我将使用什么来显示列的值 $a = get_by_sum($col,$id); // $a will select from sql sum of visit where id is equal to sent id 如果我打印$a,我将获得以下输出: Array ( [0] => stdClass Object ( [SUM(column)] => 180 ) ) 如何在php页面中查看

我将使用什么来显示列的值

 $a = get_by_sum($col,$id); 
 // $a will select from sql sum of visit where id is equal to sent id
如果我打印$a,我将获得以下输出:

Array 
    ( 
    [0] => stdClass Object 
        (
        [SUM(column)] => 180 
        ) 
     ) 
如何在php页面中查看该列? 我的意思是,我想把显示结果的echo放在我的php页面中

我希望,您应该使用
echo$a[0]>总和


如果您只想在页面上显示“180”,可以执行以下操作:

echo $a[0]->sum;
如果有多个值,则必须按如下所示执行foreach()

foreach ($a as $value) {
    echo $value->sum;
}
但在您的SQL查询中,我建议您在求和(**)后加一个别名,以获得一个有意义的键,比如

SELECT SUM(xxx) as your_alias_name FROM ... 
谢谢大家,

所有的答案都是对的,但问题是我在总数之后没有别名

我是这样解决的

我添加别名 “从中选择SUM(**)作为别名”

输出更改为

Array ( [0] => stdClass Object ( [alias] => 180 ) )
然后我使用代码

echo $a[0]->alias;

这允许我在我的页面中查看180:)

在查询中使用别名,然后使用
echo$a[0]->sum
;谢谢,但它没有显示任何内容。谢谢,问题是我没有在SUM()后面加别名