Welcome Guest, Not a member yet? Register   Sign In
[RESOLVED]Limit problem
#1

[eluser]Gerep[/eluser]
Hi fellas,

I have a LoteModel:

Code:
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:

Code:
$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:

Code:
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 =)
#2

[eluser]Gerep[/eluser]
I have found the problem but not the solution:

The LIMIT only accepts LIMIT(10,20) and not LIMIT('10,20') as I'm doing.

I don't know how to solve this, anyone?
#3

[eluser]Jocke[/eluser]
The limit method only takes number I think. You are trying to pass a string into it. Try redo your method to have 2 params for limits.

Code:
$start = 10;
$end = 20;
$this->db->limit($start, $end);
#4

[eluser]Gerep[/eluser]
Thanks jock3 that solved the problem, not the way I wanted but it's working now =)
#5

[eluser]KarlBallard[/eluser]
You could keep doing it the way you are now, but simply you function a little..

Code:
<?php

public function selecionar($where = NULL, $limit = NULL, $order_by = NULL)
{

    if(!is_null($where))
    {
        $this->db->where($where);
    }

    if(!is_null($limit))
    {
        // Let's explode the string... Mwhahahaha!
        $new_limit = explode(',', $limit);
        $this->db->limit($new_limit[0], $new_limit[1]);
    }

    if(!is_null($order_by))
    {
        $this->db->order_by($order_by);
    }

    return $this->db->get(_LOTE_);//_LOTE_ is a constant for my table name
}




Theme © iAndrew 2016 - Forum software by © MyBB