我现在处于私人测试状态,我希望能够获得上周没有活跃的人员名单。我在codeigniter中构建了这个
模型:
public function inactive_two_weeks($data) {
$this->db->select('users.id, users.username, users.email, photo.created_on');
$this->db->from($this->table);
$this->db->join('photo', 'users.id = photo.userId');
$this->db->where('photo.created_on NOT BETWEEN FROM_UNIXTIME('. $data .') AND FROM_UNIXTIME('. now().')');
$this->db->distinct();
$this->db->order_by('photo.created_on', 'desc');
return $this->db->get()->result_array();
}
在我的控制器中,我创建了$data
attribude,这只是strtotime('-1 week');
我现在所得到的似乎是每个在上周之前发布的人,这几乎是正确的。我只是需要它才能显示那些在日期范围内没有发布的人吗?
编辑:此外,我需要检查用户帐户是否少于1周
$this->db->where('users.joined <', $data);
但这似乎没有做任何事情
答案 0 :(得分:1)
您应该只加入最新记录,然后只选择那些没有记录的记录:
public function inactive_two_weeks($data) {
$this->db->select('users.id, users.username, users.email, photo.created_on');
$this->db->from($this->table);
$this->db->join('photo', 'users.id = photo.userId AND photo.created_on BETWEEN FROM_UNIXTIME('. $data .') AND FROM_UNIXTIME('. now().')', 'left');
$this->db->where('photo.created_on IS NULL');
$this->db->distinct();
return $this->db->get()->result_array();
}
答案 1 :(得分:0)
我使用少于查询
的地方public function inactive_two_weeks($data) {
$this->db->select('users.id, users.username, users.email, photo.created_on');
$this->db->from($this->table);
$this->db->join('photo', 'users.id = photo.userId');
$this->db->where('photo.created_on <', 'datenow');// i edit the where part maybe i give you an idea
$this->db->distinct();
$this->db->order_by('photo.created_on', 'desc');
return $this->db->get()->result_array();
}