gpt4 book ai didi

php - codeigniter 中的事件记录求和

转载 作者:行者123 更新时间:2023-11-29 01:08:16 25 4
gpt4 key购买 nike

我想找到投票总数并使用 codeigniter和MySQL。在我的投票表中,我有一列显示投票类型 0 表示反对票,1 表示赞成票 我如何生成一个看起来像这样的 sql

SELECT sum(type) FROM `votes` WHERE questions_id=1

使用 codeigniter 数据库类

干杯

最佳答案

这应该可以解决问题:

$this->db->select('SUM(type) as score');
$this->db->where('question_id',1);
$q=$this->db->get('votes');
$row=$q->row();
$score=$row->score

您的 $score 变量现在包含该特定问题的 type 的总和。

希望对您有所帮助!

关于php - codeigniter 中的事件记录求和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5085374/

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