Vidya_tr Posted April 18, 2009 Share Posted April 18, 2009 I have a list of record displayed and a checkbox against each of them. I need to select the checkboxes to delete the records.After selecting ,on clicking the DELETE button the records should be deleted from database and should be cleared from the list. Can i do this with php and javascript alone. or Is it possible only with Ajax??? How can I retrive the values of the checked checkboxes and delete the records? Pls help me. I googled a lot .But not able to get a clear idea.I am new to php and not familiar with Ajax. Please help me to find the solution... Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted April 18, 2009 Share Posted April 18, 2009 You can do it with just PHP, by having it as a form and posting it to a processing page which deletes all records WHERE the id is in the array of checkboxes. AJAX is just for making it cool so the page doesn't need to reload. There isn't any real point of it in this case. Basically, you have a list of checkboxes: <input type="checkbox" name="deleteme[]" value="1"> Check 1<br /> <input type="checkbox" name="deleteme[]" value="2"> Check 3<br /> <input type="checkbox" name="deleteme[]" value="3"> Check 3<br /> Notice how we have created an array of the checkboxes. So when you post and do this: print_r($_POST['deleteme']); All of the selected checkbox values will be in an array. So to use it in a query you use implode() to turn it into a string seperated by commas then delete. mysql_query("DELETE FROM records WHERE id IN('" . implode(",", $_POST['deleteme']) . "')") or die("Error: ".mysql_error()); Hope that makes some sense. Quote Link to comment Share on other sites More sharing options...
Vidya_tr Posted April 18, 2009 Author Share Posted April 18, 2009 thanks for the help... But in the solution you provided ,is it necessary that I should have the name of the checkbox in the database since you use it in the query. My page that displays the records and the checkboxes are created dynamically. Quote Link to comment 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.