我正在使用我的 sql 2008 db 使用 CI 分页助手。
我在模型上的功能是:
function get_data($limit, $offset) {
$billing_db = $this -> load -> database('billing', TRUE);
$billing_db -> select('stuff, stuff2, stuff3');
$billing_db -> from('mytable');
$billing_db -> limit($limit, $offset);
$this -> db -> order_by("id", "asc");
$q = $billing_db -> get();
return $q;
}
现在在我的控制器上,我调用了如下函数:
$data['billers'] = $this -> billing_model -> get_data(10, $this -> uri -> segment(3));
当我默认打开页面时,它会正确显示 10 个条目。
然后当我更改页面时问题就开始了,假设我单击下一步。
现在 url 段 3 是 10。它应该从第 10 个条目开始并限制为 10。
但发生的事情是它从条目 1 开始并显示 20 条记录。
每次偏移量变高时,它只会从头开始显示更多记录。
有什么问题?
/**
* Limit string
*
* Generates a platform-specific LIMIT clause
*
* @access public
* @param string the sql query string
* @param integer the number of rows to limit the query to
* @param integer the offset value
* @return string
*/
function _limit($sql, $limit, $offset)
{
$i = $limit + $offset;
return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql);
}