简体   繁体   中英

Codeigniter Active Record Limit

I have the following code that is working but I want use limit to show only 10 results ordered by ID

$this->db->select('*');
        $this->db->from('quotes');
        $this->db->join('quotes_detail', 'quotes_detail.id_rfq = quotes.id_rfq');
        $this->db->join('clients', 'clients.id = quotes.id_company');
        $this->db->limit(10,1);

        $query = $this->db->get();
        $result = $query->result();
        return $result; 

with the limit code lines, doesn't show anything, but if I remove the line the query works very well.

can anyone help me with this?, thank you.

$this->db->limit(1,10);

I think your query did

SELECT ...... LIMIT 10,1;

It should do

SELECT ...... LIMIT 1,10;
$this->db->limit(10);    // if you don't have offset
$this->db->limit(10, 0);     // if you have offset value 
this->db->limit(10,1);

First parameter is a limit. The second parameter lets you set a result offset.

If you want to get something by id use:

$this->db->where('id', $some_id);

or if you have array:

$this->db->where_in('id', $some_ids_in_array);

And if you want to order by id use:

$this->db->order_by('id', 'desc'); // or asc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM