如何在codeigniter中使用下面给出的SQL?如何在codeigniter中使用下面给出的SQL语句?
select *
from borrow_book
where isbn=(select isbn
from add_book
where author='$author)
如何在codeigniter中使用下面给出的SQL?如何在codeigniter中使用下面给出的SQL语句?
select *
from borrow_book
where isbn=(select isbn
from add_book
where author='$author)
试试这个
$query = $this->db
->select("*")
->from("borrow_book")
->where("isbn=(select isbn from add_book where author='".$this->db->escape_str($author)."')",NULL,false)
->get();
我只想补充,我不熟悉你的数据库结构,但我想大多数的时间加入会比一个子查询
更好使用此
$query= $this->db->query("SELECT borrow_book.*
FROM borrow_book, add_book
WHERE borrow_book.isbn= add_book.isbn AND add_book.author = '$author'");
$result= $query->result_array();
return $result;
使用$this->db->query();
$query=$this->db->query("select * from borrow_book
where isbn=(select isbn from add_book
where author='$author')");
$response=$query->result();
欲了解更多详情http://www.codeigniter.com/user_guide/database/index.html