• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Delete multiple rows from database table

#5
(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 need to be run outside your foreach, as you need to populate $ids array with all $id elements.
PHP Code:
$ids = [12345]; // Id's to delete.
$deleteImages $imagesModel->whereIn('id_article'$ids)->delete();
$deleteArticles $articlesModel->whereIn('id'$ids)->delete(); 

This is the solution for delete multiple rows:

PHP Code:
$id $this->request->getPost('checkbox');
        
$ids = [];

        for($count 0$count count($id); $count++)
        {
          $ids[] = $id[$count];
        }

        $articlesModel = new ArticlesModel();
        $imagesModel = new ImagesModel();
        $deleteImages $imagesModel->whereIn('id_article'$ids)->delete();
        $deleteArticles $articlesModel->whereIn('id'$ids)->delete(); 
Reply


Messages In This Thread
RE: Delete multiple rows from database table with checkbox - by eleumas - 05-06-2020, 07:46 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.