[英]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我有以下有效的代码,但我想使用 limit 只显示按 ID 排序的 10 个结果
$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:如果您想通过 id 获取某些东西,请使用:
$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:如果您想按 id 订购,请使用:
$this->db->order_by('id', 'desc'); // or asc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.