【发布时间】:2011-11-01 17:30:01
【问题描述】:
在我的文章 CURD 列表中,我需要使用多种条件从数据库中获取文章,在获取符合条件的文章数量(无限制)后,我需要获取前 10 篇符合条件的文章(限制 10)。所以我想保持activerecord状态,如果可能的话,我不需要再写那些'where'。这是我的代码:
//select num
$this->db->select('count(*) as num')
//conditions
$this->db->where/or_where/having/order_by//many conditions...
//get num
$num = $this->db->get('articles')->first_row()->num;
//get articles
$this->db->limit(10);
$articles = $this->db->get('articles')->result();
当我完成第一个查询时,活动记录状态为空,所以第二个查询是错误的。有什么办法可以保留吗?
【问题讨论】:
标签: php mysql codeigniter activerecord