CodeIgniter 的限制问题
我有一个 LoteModel:
public function selecionar($where = NULL, $limit = NULL, $order_by = NULL) {
if(!is_null($where)) {
$this->db->where($where);
}
if(!is_null($limit)) {
$this->db->limit($limit);
}
if(!is_null($order_by)) {
$this->db->order_by($order_by);
}
return $this->db->get(_LOTE_);//_LOTE_ is a constant for my table name
}
我这样称呼它:
$config['per_page'] = '5';
$limite = $config['per_page'].','.$this->uri->segment(3); //the segment is ok, I receive it
$lotes = $this->LoteModel->selecionar(array('quadra_id'=>$quadra_id, 'lote_status'=>1), $limite, 'lote_endereco');
我已经检查了该查询的 SQL 结果:
SELECT * FROM (`realestate_lote`) WHERE `quadra_id` = '1' AND `lote_status` = 1 ORDER BY `lote_endereco`
问题是,它不会生成我的 LIMIT,只有当我将其添加到 LoteModel 方法中时它才会起作用。
我正在处理分页。
预先感谢您的任何帮助=)
I have a LoteModel:
public function selecionar($where = NULL, $limit = NULL, $order_by = NULL) {
if(!is_null($where)) {
$this->db->where($where);
}
if(!is_null($limit)) {
$this->db->limit($limit);
}
if(!is_null($order_by)) {
$this->db->order_by($order_by);
}
return $this->db->get(_LOTE_);//_LOTE_ is a constant for my table name
}
and I call it like this:
$config['per_page'] = '5';
$limite = $config['per_page'].','.$this->uri->segment(3); //the segment is ok, I receive it
$lotes = $this->LoteModel->selecionar(array('quadra_id'=>$quadra_id, 'lote_status'=>1), $limite, 'lote_endereco');
I have checked the SQL result for that query:
SELECT * FROM (`realestate_lote`) WHERE `quadra_id` = '1' AND `lote_status` = 1 ORDER BY `lote_endereco`
The thing is, it’s not generating my LIMIT, it will only work if I add it to the LoteModel method.
I’m working with pagination.
Thanks in advance for any help =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能将像“5,1”这样的字符串传递给 CI 的 ActiveRecord limit 函数。
该函数需要两个参数。
用“,”分割限制字符串并传递两个值,如下例所示。
希望这有帮助...
You can't pass a string like "5,1" to CI's ActiveRecord limit function.
The function requires two parameters.
Split the limit string by "," and pass the two values like the example below.
Hope this helps...