CodeIgniter Forums
getting the max id - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: getting the max id (/showthread.php?tid=47137)



getting the max id - El Forum - 11-28-2011

[eluser]Unknown[/eluser]
hi guys. i would like to get the max id, and then use that to determine the id of the record that i will be adding... here is the code that i came up with


Model :
Code:
$this->db->select_max('id');
   $query = $this->db->get('users');
   return $query->result();
Controller:
Code:
$this->load->model('crudModel');
   $maxId= $this->crudModel->maxid();
   $maxId2=$maxId++;

the problem with this code is that, whenever i try adding using the maxid2, an error occurs because according to it, my code is returning an array, how can I fix this? thank you very much for helping!