我正在处理"发票表";。它具有";invoice_id";以及";金额";字段。我需要获取"0"的最新值;金额";最近插入的";invoice_id";
代码为:
$camount = $this->db->select_max('invoice_id')->get_where('invoice', array('invoice_id' => $this->input->post('invoice_id')))->row()->amount;
您可以在primary key
列上使用order by des
c,如下所示
注意:如果主键是invoice_id
,那么为什么要放在哪里条件下呢?
// add your where conditions e.g: $this->db->where('Field / comparison', 'value');
$this->db->order_by('invoice_id', 'desc');
$invoice = $this->db->get('invoice')->row_array();
if($invoice){
$camount = $invoice['amount'];
}