2015-12-01 45 views
0

在我笨應用程序,我有一個命名爲ims_orderdetails其中包含了不同的領域,但都是o_id具體情況關注領域表相同的值代表訂單id狀態其中可能包含正在進行或已完成。 我只想檢查ims_orderdetails的狀態列是否具有標記爲已完成的所有值。 到目前爲止,我在我的模型中有這段代碼,但無法正常工作。活動記錄,來檢查列的包含各領域

$this->db->from('ims_orderdetails'); 
$this->db->select('count(distinct status)'); 
$this->db->where('o_id',$data); 
$result = $this->db->get(); 

圖像:ims_orderdetails enter image description here

回答

0
$this->db->from('ims_orderdetails'); 
$this->db->where('o_id',$data); 
$this->db->where('status',1); // 1 = completed, 0 = In progress 
$result = $this->db->get(); 

$this->db->from('ims_orderdetails'); 
$this->db->where('o_id',$data); 
$result2 = $this->db->get(); 

if ($result->num_rows() == $result2->num_rows()) 
    return true; 
else 
    return false; 
+0

感謝您的回答。但是當我使用你的代碼這樣。$ this-> db-> from('ims_orderdetails'); $ this-> db-> select('count(distinct status)'); $ this-> db-> where('o_id',$ data); $ this-> db-> where('status','completed'); // 1 =完成,0 =進行中 $ result = $ this-> db-> get(); if($ result-> num_rows()== 1) echo「true」; //所有標記爲已完成的值 else echo「false」; \t \t 回聲$ result-> NUM_ROWS(); –

+0

它在這兩種情況下給予真正的我有重複的記錄,我的訂單詳細信息表包含2行與o_id 46兩行有狀態完成它給人真實,如果我改變狀態在進步。」它劇照給人true1 –

+0

刪除 $ this-> db-> select('count(distinct status)'); – AldoZumaran

0

我發現我的回答我的作品。

$this->db->from('ims_orderdetails'); 
$this->db->select('count(*)'); 
$this->db->where('o_id',$data); 
$this->db->not_like('status', 'completed'); 
$result = $this->db->get(); 
$res = $result->row_array(); 
if($res['count(*)']==0){ 
// do something 
}