【发布时间】:2019-02-12 20:14:33
【问题描述】:
我正在使用代码点火器,并且正在构建一个查询以返回有多少人参加了活动。所以我可以取这个数字并试着算出一个百分比。
我遇到的问题是我正在尝试根据 Codeigniter 3 Docs 构建查询,但由于某种原因我返回了错误的结果,根本无法弄清楚原因。
首先是我正在查询的数据库中的表:
这是我从控制器调用的函数:
public function get_event_attendance_percentage($id) {
$this->db->select('*');
$this->db->from('attendance');
$this->db->where('event_id', $id );
$this->db->where('attended', 1 );
$attendancecount = $this->db->get();
return count($attendancecount);
}
我从我的出勤表中选择所有,然后我声明我希望所有来自 id 17 的活动的出席,然后我还说明出席的位置 = 1
我想返回数字 3,但我返回的是数字 1。
谁能帮我看看哪里出错了?
在@Vickel 的感激帮助下,我完成了这项工作。以下是返回正确结果的查询:
public function get_event_attendance_percentage($id) {
$this->db->select('*');
$this->db->from('attendance');
$this->db->where('event_id', $id );
$this->db->where('attended', 1 );
$attendancecount = $this->db->get();
return $attendancecount->num_rows();
}
【问题讨论】:
-
另外请参考下面我的回答。 stackoverflow.com/questions/54658052/…
标签: jquery database codeigniter model