我的'期间'表看起来像这样
_________________________________________
| startdate | enddate | personID | points |
| 01/01/15 | 01/15/15| 1 | 5 |
| 01/01/15 | 01/15/15| 2 | 5 |
| 01/01/15 | 01/15/15| 3 | 5 |
| 01/16/15 | 01/30/15| 4 | 5 |
| 02/01/15 | 02/15/15| 1 | 5 |
| 02/01/15 | 02/15/15| 5 | 5 |
现在在我的视图文件中,我有2个选择输入,用户可以选择现有的startdate,另一个是enddate。当用户是personID#1时怎么可能?
If user whose UserID is 1, selected
startdate = 01/01/15
enddate = 02/15/15
...it would display 10 as the total points
If userID 1 selected
startdate = 02/01/15
enddate = 02/15/15
...it would display 5 as the total points?
答案 0 :(得分:0)
我会尝试这样的事情:
function model_method($data) {
$this->db->select("COUNT(points)");
$this->db->from('periods');
$this->db->where("personID", $data['userID']);
$this->db->where("startDate >=", $data['startDate']);
$this->db->or_where("enddate <=", $data['endDate']);
$query = $this->db->get();
return $query->result();
}