Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1K
Vistas
select * from table where id = select max id in codeigniter

How to get data where id = last id in table and show all value not one value ?

I have table name=tb_invoice and 3 column (id, month, year) How to get 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 show id, how to show all value (id, month, year)?

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Try this

$this->db->select('id, month, year')->order_by('id','desc')->limit(1)->get('tb_invoice')->row('id');
over 4 years ago · Santiago Trujillo Denunciar

0

Try using insert_id.

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

Or you can use

$this->db->select_max('{primary key}');
$query  = $this->db->get('tb_invoice');
return  = $query->row_array();
over 4 years ago · Santiago Trujillo Denunciar

0

Please Try this:

$maxid = $this->db->query('SELECT MAX(id) AS `maxid` FROM `tb_invoice`')->row()->maxid;

UPDATE

This will work even if your table is empty (unlike my example above):

$maxid = 0;
$row = $this->db->query('SELECT MAX(id) AS `maxid` FROM `tb_invoice`')->row();
if ($row) {
    $maxid = $row->maxid; 
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda