2013-02-03 36 views
1

我試圖得到像select * from bookdetails where display_id = $id with few foreign key join condition無法使用從哪裏得到的結果和笨

我寫了下面的查詢結果加入條件,但它顯示類似的錯誤:

Fatal error: Call to a member function num_rows() on a non-object in C:\xampp\htdocs\project at line432` i.e *if ($query->num_rows() > 0)...

模型。 PHP

public function get_all_book_list_atHomeTop($id, $limit, $start) 
{ 
    $this->load->database(); 
    $this->db->limit($limit, $start); 
    $this->db->get_where('bookdetails', array('display_id' => $id)); 

    //-------join condition ------------------ 


    //------------Ends here Join condition 
    $query = $this->db->get(); 

    if ($query->num_rows() > 0) 
    { 
     foreach ($query->result() as $row) 
     { 
      $data[] = $row; 
     } 
     return $data; 
    } 
    return false; 
} 

回答

2

您在get()功能缺失的表名:

$query = $this->db->get('bookdetails'); 

或者你可以簡單地用get_where()聲明你必須在一開始替換:

$query = $this->db->get_where('bookdetails',array('display_id'=>$id)); 
+0

新的疑問:我想情況下,我上面的查詢添加一個順序。即:'orderby auth_lastname'。這個怎麼做? –

+0

只需將上面的'get'行(或上面的連接):'$ this-> db-> order_by('auth_lastname','ASC');' – Shomz

+0

感謝您的幫助。 –