|
本帖最后由 深深的呼吸 于 2013-7-6 10:12 编辑
我要通过CodeIgniter的Active Record生成一个查询语句,SELECT `ID`, `post_author`, `post_title`, `post_name` FROM (`tt_posts`) WHERE `post_author` = '徐巍' OR `post_title` LIKE '%徐巍%' ORDER BY `ID` desc LIMIT 8,即用where有用like,但是中间是OR连接,怎么弄?
我是这样的写的:
PHP复制代码
$this->db->select('ID,post_author,post_title,post_name');
$this->db->where('post_author',$author);
$this->db->or_like('post_title',$author);
$this->db->order_by('ID','desc');
$result=$this->db->get('posts',8);
复制代码
生成的查询语句:
SELECT `ID`, `post_author`, `post_title`, `post_name` FROM (`tt_posts`) WHERE `post_author` = '徐巍' AND `post_title` LIKE '%徐巍%' ORDER BY `ID` desc LIMIT 8
我要求的sql语句是:
SELECT `ID`, `post_author`, `post_title`, `post_name` FROM (`tt_posts`) WHERE `post_author` = '徐巍' OR `post_title` LIKE '%徐巍%' ORDER BY `ID` desc LIMIT 8
试了几个方法了都不行,只能自己写完整的sql语句,怎样使用CodeIgniter的Active Record达到这样的效果?
|
|