[英]Codeigniter Active Record Limit
我有以下有效的代碼,但我想使用 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;
使用限制代碼行,不顯示任何內容,但如果我刪除該行,則查詢效果很好。
誰能幫我解決這個問題,謝謝。
$this->db->limit(1,10);
我認為你的查詢沒有
SELECT ...... LIMIT 10,1;
它應該做
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);
第一個參數是限制。 第二個參數允許您設置結果偏移。
如果您想通過 id 獲取某些東西,請使用:
$this->db->where('id', $some_id);
或者如果你有數組:
$this->db->where_in('id', $some_ids_in_array);
如果您想按 id 訂購,請使用:
$this->db->order_by('id', 'desc'); // or asc
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.