defeated Posted April 15, 2009 Share Posted April 15, 2009 I want to do something and I have no idea how to go about it. I am displaying the contents of my db out into a table. Each line of the table is a result row from mysql with its own id. I have added a column of checkboxes to the side of the table. I want to be able to select x number of rows via the check boxes and then click a button that sends information to a page to delete all those rows with checked check boxes. Logic has escaped me. I guess I want to turn the table into a form and return an array of all the row id's that are checked... that way I can do a foreach on the array to delete each one. ??? Am I barking up the wrong tree? How would you do it? Link to comment https://forums.phpfreaks.com/topic/154205-solved-form-help-required-apply-within/ Share on other sites More sharing options...
ober Posted April 15, 2009 Share Posted April 15, 2009 Your suggested method will work fine. Link to comment https://forums.phpfreaks.com/topic/154205-solved-form-help-required-apply-within/#findComment-810699 Share on other sites More sharing options...
defeated Posted April 15, 2009 Author Share Posted April 15, 2009 ok, but how do I assign the row id value to the checkbox? echo "<tr><td>".$id."</td><td>".$name."</td><td>".$subject."</td>"; echo "<td><input type='checkbox' name='whatever' /></td></tr>"; echo "<input type='hidden' name='row' value='".$id."' /> how do I associate the checkbox with that particular row? Link to comment https://forums.phpfreaks.com/topic/154205-solved-form-help-required-apply-within/#findComment-810707 Share on other sites More sharing options...
laffin Posted April 15, 2009 Share Posted April 15, 2009 JUst Remember to name your array with the appended [] like <input type="checkbox" name="delarray[]" value="xxx"> where xxx is the id of the row ya want to delete. this will show up in php as u guessed <?php $delarray=$_POST['delarray']; ?> Link to comment https://forums.phpfreaks.com/topic/154205-solved-form-help-required-apply-within/#findComment-810710 Share on other sites More sharing options...
soak Posted April 15, 2009 Share Posted April 15, 2009 Just a quick note, to get an array returned as the post data set the name field on each of your checkboxes like name="NAME[]" where NAME is the name of the field. The square brackets should make $_POST[NAME] return an array (note that you should still sanity check it before attempting processing in case none are selected). Just seen your update, like this: echo "<tr><td>".$id."</td><td>".$name."</td><td>".$subject."</td>"; echo "<td><input type='checkbox' name='whatever[]' value=".$id."/></td></tr>"; Link to comment https://forums.phpfreaks.com/topic/154205-solved-form-help-required-apply-within/#findComment-810713 Share on other sites More sharing options...
defeated Posted April 15, 2009 Author Share Posted April 15, 2009 Aha! value= I didn't know you could assign a value to a checkbox. Thank you all. I'm on to multiple actions for my form now... Link to comment https://forums.phpfreaks.com/topic/154205-solved-form-help-required-apply-within/#findComment-810727 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.