在添加另一个限制语句CodeIgniter之前计数行? [英] Count rows before adding a further limit statement CodeIgniter?

查看:99
本文介绍了在添加另一个限制语句CodeIgniter之前计数行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题...

I have ran into a problem...

我有一堆的像这样的雕像...

I have a bunch of where statments like so...

$this->db->where('Pool', "1");
$this->db->where('Bedrooms >=', "3");

然后一个限制语句

$this->db->limit($limit, $offset);

最后我的get语句

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

我的问题是我需要在limit语句之前计算结果,行没有限制..所以我试过这个..

$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');

这个计算我的行与where语句罚款..但是,get语句现在获取记录没有

This counts my rows with the where statements fine.. However, the get statement now gets records without the previous where statements working.

它不可见,但是有大量的代码处理更多的语句,并在URL中抓取东西,所以我不想执行检索数据两次以修复此问题...

It's not visible, but there is a large amount of code handling more where statements, and grabbing things in urls, So I'd prefer not to perform the retrieval of data twice in order to fix this...

干杯!

推荐答案

$get_data = $this->your_model->get_data();
$data     = $get_data['data'];
$count    = $get_data['count'];

模型

function get_data($limit = 10, $offset= 0)
{
    $table = 'table-name';
    $where = array('Pool' => 1, 'Beedrooms >=' 3);

    $return['data']  = $this->db->from($table)->where($where)->limit($limit, $offset)->get();
    $return['count'] = $this->db->from($table)->where($where)->count_all_results();

    return $return;
}

这篇关于在添加另一个限制语句CodeIgniter之前计数行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆