Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php codeigniter中的活动记录求和_Php_Mysql_Codeigniter - Fatal编程技术网

Php codeigniter中的活动记录求和

Php codeigniter中的活动记录求和,php,mysql,codeigniter,Php,Mysql,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->

我想找到投票总数,我正在使用和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
变量现在包含该特定问题的
类型的总和

希望有帮助