¿Cómo obtener datos donde id = último id en la tabla y mostrar todos los valores, no un valor?
Tengo el nombre de la tabla = tb_invoice y 3 columnas (id, mes, año) ¿Cómo obtener la última identificación y mostrar el resultado (id, mes, año) en codeigniter? aquí mi código:
$this->db->select_max('id'); $query = $this->db->get('tb_invoice'); return = $query->row_array();el resultado solo muestra la identificación, ¿cómo mostrar todos los valores (identificación, mes, año)?
Prueba esto
$this->db->select('id, month, year')->order_by('id','desc')->limit(1)->get('tb_invoice')->row('id');Intenta usar insert_id.
$this->db->insert_id(); $query = $this->db->get('tb_invoice'); return = $query->row_array();O puedes usar
$this->db->select_max('{primary key}'); $query = $this->db->get('tb_invoice'); return = $query->row_array();Por favor, prueba esto:
$maxid = $this->db->query('SELECT MAX(id) AS `maxid` FROM `tb_invoice`')->row()->maxid;ACTUALIZAR
Esto funcionará incluso si su tabla está vacía (a diferencia de mi ejemplo anterior):
$maxid = 0; $row = $this->db->query('SELECT MAX(id) AS `maxid` FROM `tb_invoice`')->row(); if ($row) { $maxid = $row->maxid; }