2012-10-28 45 views
0

我使用codeigniter爲我的網站,但我有一個問題,我做了腳本誰從不同的表中返回行。但它寫我錯誤試圖獲得非對象的屬性。這是我的代碼。問題在哪裏?Codeigniter獲得行

 $this->db->select('*'); 
     $this->db->from('orders'); 
     $this->db->where('order_id',$order_id); 
     $array_keys_values = $this->db->get(); 
     $row = $array_keys_values->row(); 

     $this->db->select('*'); 
     $this->db->from('pacients'); 
     $this->db->where('pacient_account_id',$row->order_pacient_id); 
     $array_keys_values2 = $this->db->get(); 
     $row2 = $array_keys_values2->row(); 

     $this->db->select('*'); 
     $this->db->from('doctors'); 
     $this->db->where('doctor_account_id',$doctor_id); 
     $array_keys_values3 = $this->db->get(); 
     $row3 = $array_keys_values3->row(); 
+0

這是錯誤http://i45.tinypic.com/2lwuqt3.jpg –

+0

您是否在數據庫配置中啓用了'db_debug'?似乎'$ this-> db-> get()'返回false,這可能意味着生成的查詢是無效的(沒有這樣的表/列)等等。 – complex857

+0

是的,我把db_debug設置爲TRUE。但我的問題是確定的。 –

回答

2

嘗試

$this->db->select('*'); 
$this->db->from('orders'); 
$this->db->where('order_id',$order_id); 
$array_keys_values = $this->db->get();  
if ($array_keys_values->num_rows() > 0) { 
    foreach ($array_keys_values->result() as $row) { 
     // now you can work with $row 
    } 
} 

$this->db->select('*'); 
$this->db->from('pacients'); 
$this->db->where('pacient_account_id',$row->order_pacient_id); 
$array_keys_values2 = $this->db->get(); 
if ($array_keys_values2->num_rows() > 0) { 
    foreach ($array_keys_values2->result() as $row2) { 
     // now you can work with $row2 
    } 
} 

$this->db->select('*'); 
$this->db->from('doctors'); 
$this->db->where('doctor_account_id',$doctor_id); 
$array_keys_values3 = $this->db->get(); 
if ($array_keys_values3->num_rows() > 0) { 
    foreach ($array_keys_values3->result() as $row3) { 
     // now you can work with $row3 
    } 
} 
0

未返回行。使用帶有num_rows()> 0的if語句來檢查