phpcodeignitermaxcodeigniter-3query-builder

select * from table where id = select max id in CodeIgniter


How can I get the table row where id = last id and show all column values (not just one column value)?

I have table name=tb_invoice and 3 column (id, month, year).

How can I get the whole row with the last id and show result (id, month, year) in CodeIgniter?

here my code :

$this->db->select_max('id');
$query = $this->db->get('tb_invoice');
return $query->row_array();

The result just shows the id, how to show all value (id, month, year)?


Solution

  • $this->db
        ->select('id, month, year')
        ->order_by('id','desc')
        ->limit(1)
        ->get('tb_invoice')
        ->row('id');