delete multiple table rows with checkbox in php , jquery and ajax

In this post i am going to show you how you can delete multiple rows from the html table as well as from the database. First you need to add an extra column in the table for the checkbox. We will also have a checkbox in the header of the html table to select/unselect multiple rows. If you dont know how to implement select all checkbox checkout my previous post select/unselect Multiple rows . The second thing we need is a button to delete all the selected rows. When the button will be clicked IDS of all the selected rows are sent to the delete.php. Below is the code for “table.php”.

table.php

You need to include the jquery file in your code using script tag to run the below code.
JS Code:

CSS Code:

 

delete-multiple-rows-from-html-table

delete-multiple-rows-from-html-table

Css code and JS code are included in “table.php”. Delete.php recieves the request and extracts the array of IDs and deletes the rows with those IDs. If the deletion is successful the the control goes back to the table.php file and it removes the rows from the html table as well. But if error occurs while deletion an error message is returned to the table.php and displays the error message. Below is the php code for dele.php.

All the code is tested in Firefox , Chrome , Opera and Safari. You can downoad the source files by clicking the button below.
Download Source
Also check : Delete single html row with animation

If you have any queries don’t hesitate to leave a comment i will get back to you as soon as possible. And dont forget to share it with your friends. Till next time HAPPY CODING!

8 thoughts on “delete multiple table rows with checkbox in php , jquery and ajax

  1. Denis Reppucci

    For selecting multiple rows, we are going to use checkbox input for submitting selected rows reference. While implementing multiple rows update or delete, we need to follow some steps.

    Reply
    1. Danyal Fayyaz Post author

      @Denis We are using checkbox for selecting multiple rows and the Delete button to send the IDs of the selected rows to the delete.php file which deletes row records by ID.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

CommentLuv badge