获取逐步查询签名的结果

问题描述 投票:0回答:1

我需要做这样的事情:

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 + offset和limit):

SELECT *
FROM `table`
WHERE `account` = 'some account'
AND `subject` = 'some subject'
AND `_from` = 'name'
LIMIT 10, 5

但是$result2作为单独的查询执行:select * FROM table LIMIT10, 5

有可能实现这一点,或者我需要从头开始查询?

php database codeigniter codeigniter-3
1个回答
1
投票

LIMIT无限制()功能

result = $this->db->get('table', 0, $offset);

或使用手动选择:

$query = "SELECT *, COUNT(account) AS total FROM `table` WHERE `account` = ? AND `subject` = ? AND `_from` = ? LIMIT 0, ?";
$result = $this->db->query($query, array($account, $subject, $contact, $offset));
© www.soinside.com 2019 - 2024. All rights reserved.