2014-11-16 2 views
0

다음 코드는 최신 상태의 각 MAC에 대해 하나의 행을 가져옵니다. 내가 가지고있는 문제는 내가 한 줄을 얻었지만 최신 상태가 아니라 오히려 초기 상태라는 것이다.코드 점화 기 - 필요한 항목을 표시하지 않습니다.

function get_active_devices($min_duration, $max_duration) 
{ 
    //get all active devices DESC order 
    $this->db->distinct(); 
    $this->db->group_by('mac'); 
    $this->db->order_by("id", "desc"); 
    $this->db->select('data.mac, state, time, iot_bo.notified, iot_bo.op_state, iot_bo.Name'); 
    $this->db->where('time >', time()-$max_duration); 
    $this->db->where('time <', time()-$min_duration); 
    $this->db->join('iot_bo', 'iot_bo.mac = data.mac'); 
    $this->db->where('iot_bo.op_state', '1'); 
    $query = $this->db->get(); 
    return $query; 
} 

답변

0

먼저 distinct 및 groupBy없이 쿼리를 시도 했습니까? 당신이 원하는 결과가 전체 결과 집합에서 시작하지 않을 수도 있습니다. db 메서드를 그대로 사용하면 문제가있는 것 같지 않기 때문입니다.

+0

예, 테스트 해 보았습니다. 올바른 결과를 얻었습니다. – Simon

관련 문제