delete multiple rows using check box in PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deepti thakur
    New Member
    • Nov 2011
    • 1

    delete multiple rows using check box in PHP

    Hi ,
    I am trying to figure out why my PHP code to delete multiple value by selecting the checkbox is not working.
  • omerbutt
    Contributor
    • Nov 2006
    • 638

    #2
    what is not working? where is the code ?, any errors received , paste them here
    regards,
    Omer Aslam

    Comment

    • Bharat383
      New Member
      • Aug 2011
      • 93

      #3
      transfer the values of all checkboxes that are selected .
      save all that in one array or one variable. if you saved them into one variable then explode its seperate
      it's better to save those selected values in one array.
      after that fire delete query using loop.

      Comment

      • zorgi
        Recognized Expert Contributor
        • Mar 2008
        • 431

        #4
        Originally posted by Bharat383
        transfer the values of all checkboxes that are selected .
        save all that in one array or one variable. if you saved them into one variable then explode its seperate
        it's better to save those selected values in one array.
        after that fire delete query using loop.

        Looping and deleting is ok but probably not the best solution and is much slower than using pure SQL:

        Code:
        DELETE FROM `your_table` WHERE `id` IN (1,2,3,4)
        If you have an array of row ids that you want to delete you could do something like this:

        Code:
        $ids = array(1, 2, 3, 4);
        $sql = "DELETE FROM `your_table` WHERE `id` IN (" . implode(',', $ids) . ")";
        No need for looping.

        Comment

        • omerbutt
          Contributor
          • Nov 2006
          • 638

          #5
          @ zorgi , yes you are very right looping will not be as faster as the pure SQL , and thats where it takes the edge, and is best fastest way to delete multiple records.
          regards,
          Omer Aslam

          Comment

          • Artnessde
            New Member
            • Nov 2011
            • 13

            #6
            just my 2cent ... never forget to sanitize the input - you never know if the array of values you get from external input will be numbers all the way :-)

            Comment

            Working...