Reputation: 33
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.
Upvotes: 1
Views: 10591
Reputation: 21
$this->db->limit(10); // if you don't have offset
$this->db->limit(10, 0); // if you have offset value
Upvotes: 1
Reputation: 289
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
Upvotes: 1
Reputation: 598
$this->db->limit(1,10);
I think your query did
SELECT ...... LIMIT 10,1;
It should do
SELECT ...... LIMIT 1,10;
Upvotes: 4