Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.1K
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda