【发布时间】:2018-09-15 18:20:54
【问题描述】:
我需要这样做:
if (isset($account)) {
$this->db->where('account', $account);
}
if (isset($subject)) {
$this->db->where('subject', $subject);
}
if (isset($contact)) {
$this->db->where('_from', $contact);
}
//here i need to get result
$resul1 = $this->db->get('table');
$limit = 5; $offset =10;
$this->db->limit($limit, $offset);
//here i need to get result with offset and limit
$result2 = $this->db->get('table');
$result1 应该执行这个查询
SELECT *
FROM `table`
WHERE `account` = 'some account'
AND `subject` = 'some subject'
AND `_from` = 'name'
并且 $result2 应该执行这个查询($query1 + 偏移量和限制):
SELECT *
FROM `table`
WHERE `account` = 'some account'
AND `subject` = 'some subject'
AND `_from` = 'name'
LIMIT 10, 5
但 $result2 作为单独的查询执行:select * FROM table LIMIT10, 5
是否有可能实现这一点,或者我需要从头开始查询?
【问题讨论】:
-
如果一个查询似乎就足够了,我想知道您为什么要执行两个查询。
-
@Jamie_D 我需要确定最大页码。我正在开发一个 rest api 服务,所以我不能使用 CI 分页库。
-
@u_mulder 听起来这是不可能的(至少在 CI2 中)。
标签: php database codeigniter codeigniter-3