By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,731 Members | 1,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,731 IT Pros & Developers. It's quick & easy.

delete multiple rows using check box in PHP

P: 1
Hi ,
I am trying to figure out why my PHP code to delete multiple value by selecting the checkbox is not working.
Nov 15 '11 #1
Share this Question
Share on Google+
5 Replies

P: 638
what is not working? where is the code ?, any errors received , paste them here
Omer Aslam
Nov 16 '11 #2

P: 93
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.
Nov 21 '11 #3

Expert 100+
P: 431

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

Expand|Select|Wrap|Line Numbers
  1. 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:

Expand|Select|Wrap|Line Numbers
  1. $ids = array(1, 2, 3, 4);
  2. $sql = "DELETE FROM `your_table` WHERE `id` IN (" . implode(',', $ids) . ")";
No need for looping.
Nov 21 '11 #4

P: 638
@ 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.
Omer Aslam
Nov 21 '11 #5

P: 13
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 :-)
Nov 26 '11 #6

Post your reply

Sign in to post your reply or Sign up for a free account.