unemployment Posted January 24, 2011 Share Posted January 24, 2011 Can I use php to delete multiple rows that have a checkbox selected. I'm not sure how to go about doing this. Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/225533-delete-all-rows-with-check-box/ Share on other sites More sharing options...
msaz87 Posted January 24, 2011 Share Posted January 24, 2011 Do something like this: <?php while($row = mysql_fetch_arrary($myQuery)) { ?> <?php echo $row['title'];?> <input type="checkbox" name="delete_me[$row['ID']]"> <?php } ?> Then after the form is posted... $delete_me = $_REQUEST['delete_me']; if(!empty($delete_me)) { foreach($delete_me as $key => $value){ if($value == "on") { mysql_query("DELETE * FROM yourTable WHERE ID = '$key'") or die(mysql_error()) } } } Quote Link to comment https://forums.phpfreaks.com/topic/225533-delete-all-rows-with-check-box/#findComment-1164555 Share on other sites More sharing options...
unemployment Posted January 24, 2011 Author Share Posted January 24, 2011 Do something like this: <?php while($row = mysql_fetch_arrary($myQuery)) { ?> <?php echo $row['title'];?> <input type="checkbox" name="delete_me[$row['ID']]"> <?php } ?> Then after the form is posted... $delete_me = $_REQUEST['delete_me']; if(!empty($delete_me)) { foreach($delete_me as $key => $value){ if($value == "on") { mysql_query("DELETE * FROM yourTable WHERE ID = '$key'") or die(mysql_error()) } } } That didn't seem to work for me Quote Link to comment https://forums.phpfreaks.com/topic/225533-delete-all-rows-with-check-box/#findComment-1164571 Share on other sites More sharing options...
msaz87 Posted January 24, 2011 Share Posted January 24, 2011 Post some code Quote Link to comment https://forums.phpfreaks.com/topic/225533-delete-all-rows-with-check-box/#findComment-1164577 Share on other sites More sharing options...
mikosiko Posted January 24, 2011 Share Posted January 24, 2011 That didn't seem to work for me "seems" doesn't help much to the people here that is trying to help you. - what exactly are you getting? - which is the complete code that you are using? Quote Link to comment https://forums.phpfreaks.com/topic/225533-delete-all-rows-with-check-box/#findComment-1164580 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.