即时通讯使用活动记录,它的工作正常,但我想将$ data ["totalres"]设置为总结果,我的意思是,相同的查询,但没有LIMIT
问题是当你执行查询修饰符时,前面的语句被取消设置,所以我甚至不能在得到结果后添加$ this-> db-> limit().
有任何想法吗?我认为,为了做到这一点,"复制"查询是一种不好的做法
function get_search($start, $numrows, $filter = array())
{
...
$this->db
->select("emp")
->from('emp')
->join('empr', 'empr.b = empr.id', 'left')
->like('code', $code)
->limit($numrows, $start);
...
$q = $this->db->get();
// number of rows WITHOUT the LIMIT X,Y filter
$data["totalres"] = ???????;
if ($q->num_rows() > 0)
{
$data["results"] = $q->result();
} else {
$data["results"] = array();
}
return $data;
}
Run Code Online (Sandbox Code Playgroud) 我遇到了一个问题......
我有一堆像这样的陈述......
$this->db->where('Pool', "1");
$this->db->where('Bedrooms >=', "3");
Run Code Online (Sandbox Code Playgroud)
然后是限制声明
$this->db->limit($limit, $offset);
Run Code Online (Sandbox Code Playgroud)
最后我得到了声明
$query = $this->db->get('table-name');
Run Code Online (Sandbox Code Playgroud)
我的问题是我需要在我的限制语句之前计算结果,以获得没有限制的总行数.所以我尝试了这个..
$this->db->where('Pool', "1");
$this->db->where('Bedrooms >=', "3");
$num_rows = $this->db->count_all_results();
$this->db->limit($limit, $offset);
$query = $this->db->get('table-name');
Run Code Online (Sandbox Code Playgroud)
这将使用where语句对我的行进行计数.但是,get语句现在获取没有先前where语句工作的记录.
它是不可见的,但有大量的代码处理更多的语句,并抓住网址中的东西,所以我宁愿不执行两次数据检索,以解决这个问题...
干杯!