2011-05-18 108 views
1

我有一个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方法时才起作用。

我正在使用分页。

预先感谢任何帮助=)

+0

我已经发现了问题,但没有解决: 极限只接受LIMIT(10,20),而不是限制('10,20' ),因为我正在做。 我不知道如何解决这个问题,有人吗? – Gerep 2011-05-18 20:04:54

+0

我找到了解决这个问题的方法。我可以发送一个数组作为我的LIMIT参数: $ lotes = $ this-> LoteModel-> selecionar(array('quadra_id'=> $ quadra_id,'lote_status'=> 1),array('x'= > 10,'y'=> 20),'lote_endereco'); 或将我的LoteModel更改为: public function selecionar($ where = NULL,$ limit_start = NULL,$ limit_end = NULL,$ order_by = NULL){ – Gerep 2011-05-18 20:27:41

回答

4

你不能传递一个字符串,如“5,1”到CI的ActiveRecord的限制功能。 该功能需要两个参数。

将限制字符串拆分为“,”并传递下面的示例中的两个值。

$limit = explode(',', $limit); 
$this->db->limit($limit[0], $limit[1]); 

希望这有助于...