![]() |
help, updating excisting row in database[SOLVED] - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: help, updating excisting row in database[SOLVED] (/showthread.php?tid=28798) |
help, updating excisting row in database[SOLVED] - El Forum - 03-22-2010 [eluser]Ivar89[/eluser] hi, I recently started using codeIgniter and I am lost atm. I need to update the last row in my database, this is my code so far in model: Code: $sql = $this->db->query ('Select * From tblpage Where ID_Page = (Select Max(ID_Page) From tblpage)'); Code: { If it stays there I get a database error: how can I tell him to just update the LAST row? thanks, help, updating excisting row in database[SOLVED] - El Forum - 03-22-2010 [eluser]danmontgomery[/eluser] Code: $id['ID_Page'] = $sql; This shouldn't be an array... Furthermore, you can't pass a database result to where() (or any of the active record functions, for that matter). It would just be easier to limit and order your update query: Code: $this->db->order_by('ID_Page', 'DESC')->limit(1)->update($table_name, array('field_to_update' => 'new_value')); help, updating excisting row in database[SOLVED] - El Forum - 03-23-2010 [eluser]Ivar89[/eluser] Code: $id['ID_Page'] = $sql; Yhea I notced right after I posted that it wouldn't work... I fixed it differently because if multiple people were editing the databes they would both be editing the last row so I fixed it using a hidden field which saves the insert id and I just post it with every update. Code: Return $this->db->insert_id(); |