2013-11-21 41 views
1

我有多個條目對應於單個屬性。我需要檢索最後插入的特定ID的記錄。我想這樣的,如何檢索codeigniter中的特定屬性的最後一項

$this->db->select('*'); 
$this->db->from('tbl_appverification'); 
$this->db->where('app_no',$appno); 
$query = $this->db->get(); 
return $query_result(); 

,但我得到的所有值,其中app_no =「5665」

+0

使用笨$這個 - > DB-> insert_id函數... – vijaykumar

回答

0

$query->result()

,如果你想插入的最後的值,你應該在表列時間戳或按自動遞增的ID(desc)排序並選取第一條記錄。

例如:

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

$this->db->order_by('created', 'desc'); 
0

在date_inserted

數據庫中添加列並添加該代碼

$this->db->order_by('date_inserted','desc/asc'); 
$this->db->limit(1); 
相關問題