CodeIgniter Forums
Replace old data to new data by Group ID - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: Replace old data to new data by Group ID (/showthread.php?tid=82458)



Replace old data to new data by Group ID - flux1on - 07-12-2022

I have table like


Code:
tb_class
---------------------------------------------------------
id | group_id | name | class | hour
---------------------------------------------------------
1 | 1 | aaaaa | xi | 20
2 | 1 | bbbb | xx | 30
3 | 1 | ccccc | xq | 40
4 | 2 | dddd | zy | 10


And i implement sortable for draggable to replace old records tb_class by group_id.

Code:
tb_class
---------------------------------------------------------
id | group_id | name | class | hour
---------------------------------------------------------
4 | 2 | dddd | zy | 10
5 | 1 | eeee | qe | 60
6 | 1 | fffffff | qw | 32
7 | 1 | gggg | qq | 26
8 | 1 | hhhh | qr | 53

Can i use replace() function in Model? I need sample model to provide this


RE: Replace old data to new data by Group ID - ozornick - 07-12-2022

The "replace" method replaces the entry and applies the new ID if the entry exists. This is bad. Use the "update" method 

http://codeigniter.com/user_guide/database/query_builder.html#builder-update