无法使用codeigniter中的where和join条件获取结果

时间:2013-02-03 08:24:29

标签: php mysql codeigniter

我想获得像select * from bookdetails where display_id = $id with few foreign key join condition

这样的结果

我编写了以下查询,但它显示的错误如下:

  

致命错误:在第4行的C:\ xampp \ htdocs \ project中调用非对象的成员函数num_rows(),即* if($ query-> num_rows()> 0)...

Model.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;
}

1 个答案:

答案 0 :(得分:2)

get()函数中缺少表名:

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

或者您只需将其替换为开头的get_where()语句:

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