How to convert this update QUERY to ActiveRecord - 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: How to convert this update QUERY to ActiveRecord (/showthread.php?tid=1890) |
How to convert this update QUERY to ActiveRecord - El Forum - 07-03-2007 [eluser]MpaK69[/eluser] I have this query Code: $this->db->query('UPDATE '.$this->dbprefix.'menu SET ord_id = ord_id-1 WHERE ord_id > ?', $row['ord_id']); but I want to make this with ActiveRecord some think like this Code: $this->db->set('ord_id = ord_id-1'); can some one help with this problem? How to convert this update QUERY to ActiveRecord - El Forum - 07-03-2007 [eluser]Christopher Blankenship[/eluser] First you have to of course obtain the $row['ord_id'] and then this is what I believe you are looking for: Code: $data = array( How to convert this update QUERY to ActiveRecord - El Forum - 07-03-2007 [eluser]MpaK69[/eluser] nop if I have now more than 2000 records! If I will do it in cycle that will be tragedy How to convert this update QUERY to ActiveRecord - El Forum - 07-03-2007 [eluser]Christopher Blankenship[/eluser] Yeah with that many records that would not work very well. Oh i think i understand what you are looking for now you want it to actively update that fields ord_id subtracting 1 from it for anything greater than the supplied row ord_id. For example here would be 3 ord_id fields in the db. 127 145 198 and the supplied row ord_id was 129. 127 would not be touched while 145 would be updated to 144 and 198 would be updateed to 197 How to convert this update QUERY to ActiveRecord - El Forum - 07-04-2007 [eluser]MpaK69[/eluser] yeah, ok, I understand I cant do this with AC pattern I did it with query Code: if($neword < $oldord){ |