Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1K
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!