ari_aaron Posted March 26, 2007 Share Posted March 26, 2007 Is there a good code to delete multiple SQL entries with checkboxes? I have a form with a bunch of checkboxes with value="2512", or whatever which goes to the ID column in my SQL table. I want it so that whatever boxes that are checked are selected, so 'SELECT * FROM table WHERE ID="2323" OR ID="1234"' I probably can explain better if someone dosn't get what i'm asking. Link to comment https://forums.phpfreaks.com/topic/44384-solved-mass-delete-checkboxes/ Share on other sites More sharing options...
desithugg Posted March 26, 2007 Share Posted March 26, 2007 yea hold on gimme a sec to type it Link to comment https://forums.phpfreaks.com/topic/44384-solved-mass-delete-checkboxes/#findComment-215533 Share on other sites More sharing options...
desithugg Posted March 26, 2007 Share Posted March 26, 2007 //html form with a bit of javascript to make it easier //html code or form <head> <script type="text/javascript"> <!-- function SetAllCheckBoxes(FormName, FieldName, CheckValue) { if(!document.forms[FormName]) return; var objCheckBoxes = document.forms[FormName].elements[FieldName]; if(!objCheckBoxes) return; var countCheckBoxes = objCheckBoxes.length; if(!countCheckBoxes) objCheckBoxes.checked = CheckValue; else // set the check value for all check boxes for(var i = 0; i < countCheckBoxes; i++) objCheckBoxes[i].checked = CheckValue; } // --> </script> </head> <input type="button" onclick="SetAllCheckBoxes('myForm', 'deletelist[]', true);" value="Select All"> <input type="button" onclick="SetAllCheckBoxes('myForm', 'deletelist[]', false);" value="DeSelect All"> <form action='deletepms.php' method='post' name='myForm'> <INPUT TYPE='CHECKBOX' value='1' name='deletelist[]' multiple='multiple'>1 <INPUT TYPE='CHECKBOX' value='2' name='deletelist[]' multiple='multiple'>2 <INPUT TYPE='CHECKBOX' value='3' name='deletelist[]' multiple='multiple'>3 <INPUT TYPE='CHECKBOX' value='4' name='deletelist[]' multiple='multiple'>4 <INPUT TYPE='CHECKBOX' value='5' name='deletelist[]' multiple='multiple'>5 <INPUT TYPE='CHECKBOX' value='6' name='deletelist[]' multiple='multiple'>6 <input type='submit' value='Delete Selected'> </form> the php code that proccesses the info submit $del = $_POST['deletelist']; if($del == "") { echo "you did not select any pms"; exit; } $del2 = implode(", ", $del); //lists the values in an array seperated by commas $query = "delete FROM pm WHERE username = 'user' && id IN ($del2)"; $result = mysql_query($query) or die(mysql_error()); echo"All selected messages have been deleted."; either that or you can run like a foreach function $del = $_POST['deletelist']; foreach($del as $delete) { $query = "delete FROM pm WHERE username = 'user' && id = '$delete'"; $result = mysql_query($query) or die(mysql_error()); echo "PM #".$delete." had been deleted."; } Link to comment https://forums.phpfreaks.com/topic/44384-solved-mass-delete-checkboxes/#findComment-215538 Share on other sites More sharing options...
ari_aaron Posted March 26, 2007 Author Share Posted March 26, 2007 Thanks. I could have done that. I didn't realize it was an aray Link to comment https://forums.phpfreaks.com/topic/44384-solved-mass-delete-checkboxes/#findComment-215552 Share on other sites More sharing options...
sayedsohail Posted March 26, 2007 Share Posted March 26, 2007 Million thanks desithugg, for such wonderfull code. Link to comment https://forums.phpfreaks.com/topic/44384-solved-mass-delete-checkboxes/#findComment-215571 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.