gpt4 book ai didi

php - 从 stdClass 对象中删除 stdClass 对象和 count(post_id) ( [count(post_id)] => 1 ) 仅需要结果 1

转载 作者:行者123 更新时间:2023-11-29 10:56:51 25 4
gpt4 key购买 nike

我的 mysql 查询是:

$query=('SELECT count(post_id)  FROM comments where   post_id='.$row['post_id']);
$usercomments = $this->db->query($query);
foreach ($usercomments->result() as $comments)

我得到的输出:

stdClass Object ( [count(post_id)] => 1 )

如何获得计数值1?如何打印?

最佳答案

将您的查询更改为:

SELECT count(post_id)  FROM comments where   post_id='.$row['post_id'];

SELECT count(post_id) as post_count  FROM comments where   post_id='.$row['post_id'];
//here post_count is an ALIAS for the count(post_id)

然后获取其值,例如:

$comments->post_count;

关于php - 从 stdClass 对象中删除 stdClass 对象和 count(post_id) ( [count(post_id)] => 1 ) 仅需要结果 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42897050/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com