Delete multiple rows from database table - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Delete multiple rows from database table (/showthread.php?tid=76354) |
Delete multiple rows from database table - eleumas - 05-05-2020 PHP Code: function delete() I would like delete multiple rows from my table. I have an array of checkbox. How can i do? Thanks. RE: Delete multiple rows from database table - jreklund - 05-05-2020 You can use whereIn() to target multiple IDs. RE: Delete multiple rows from database table - eleumas - 05-05-2020 If i use this snippet: PHP Code: $deleteImages = $imagesModel->whereIn('id_article', $id)->delete(); I have an error: Code: CodeIgniter\Database\Exceptions\DatabaseException #8 Please, can you write the correct query for delete multiple rows? Thanks for help me. RE: Delete multiple rows from database table - jreklund - 05-05-2020 I think you are required to put in an array. Right now you are just entering one id. This need to be run outside your foreach, as you need to populate $ids array with all $id elements. PHP Code: $ids = [1, 2, 3, 4, 5]; // Id's to delete. RE: Delete multiple rows from database table with checkbox - eleumas - 05-06-2020 (05-05-2020, 11:35 AM)jreklund Wrote: I think you are required to put in an array. Right now you are just entering one id. This is the solution for delete multiple rows: PHP Code: $id = $this->request->getPost('checkbox'); |