![]() |
How can we delete multiple by checkbox - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: How can we delete multiple by checkbox (/showthread.php?tid=22490) |
How can we delete multiple by checkbox - El Forum - 09-11-2009 [eluser]Unknown[/eluser] I don't know how to delete multiple by checkbox in codeigniter. How can i do? for example i used to assign to url like exmple.com/index/delete/2,3,4 but i don't how can i do it? How can we delete multiple by checkbox - El Forum - 09-11-2009 [eluser]Unknown[/eluser] I’m working on some cms tool to make posts on site I used a lot of cms like Joomla, WordPress and Textpattern. Now I want to make something like that, of course not even similar to that but just for my personal use and fun. 2 things to do: 1. Option to select all checkboxes. I like something like in joomla in top there is checkbox with titles when u select it all checkbox are selected and if u uncheck it all is unchecked 2. When I press delete button all checkboxes that I select are deleted from database or moved to some other category like trash which is nice because u can in that way return some posts that u delete by mistake or some other reason Here is my code that bothers me becouse checkboxes don't work Help with Code Tags php Syntax (Toggle Plain Text) 1. <?php 2. include ('conf/config.php'); 3. include('conf/opendb.php'); 4. $sql="SELECT id, title, author, DATE_FORMAT(date, '%M %d, %Y') as sd FROM $tbl_name"; 5. $result=mysql_query($sql); 6. 7. $count=mysql_num_rows($result); 8. 9. ?> 10. <table border="0" cellspacing="0" cellpadding="0"> 11. <tr> 12. <td><form name="form1" method="post" action=""> 13. <table border="0" cellpadding="0" cellspacing="0" class="adminlist"> 14. <tr id="top"> 15. <th width="5" align="center">Id</th> 16. <th width="5" align="center">#</th> 17. <th>Title</th> 18. <th width="200" align="center">Author</th> 19. <th width="100" align="center">Date</th> 20. <th width="80" align="center">Delete</th> 21. <th width="20" align="center">Edit</th> 22. </tr> 23. <?php 24. while($rows = mysql_fetch_array($result)){ 25. ?> 26. <tr> 27. <td width="5" align="center"><? echo $rows['id']; ?></td> 28. <td width="5" align="center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td> 29. <td><? echo $rows['title']; ?></td> 30. <td width="200" align="center"><? echo $rows['author']; ?></td> 31. <td width="100" align="center"><? echo $rows['sd']; ?></td> 32. <td width="80" align="center" id="trash"><a href="delete_news.php?id=<? echo $rows['id']; ?>">Delete</a></td> 33. <td width="20" align="center" id="edit"><a href="edit_news.php?id=<? echo $rows['id']; ?>">Edit</a></td> 34. <?php 35. } 36. ?> 37. <tr> 38. <td colspan="7" align="center"><input name="delete" type="submit" id="delete" value="Delete"></td> 39. </tr> 40. <? 41. // Check if delete button active, start this 42. if($delete){ 43. for($i=0;$i<$count;$i++){ 44. $del_id = $checkbox[$i]; 45. $sql = "DELETE FROM $tbl_name WHERE id='$del_id'"; 46. $result = mysql_query($sql); 47. } 48. 49. // if successful redirect to delete_multiple.php 50. if($result){ 51. echo "<meta http-equiv=\"refresh\" content=\"0;URL=post_manage.php\">"; 52. } 53. } 54. mysql_close(); 55. ?> 56. </table> 57. </form> 58. </td> 59. </tr> 60. </table> How can we delete multiple by checkbox - El Forum - 09-11-2009 [eluser]NateL[/eluser] [quote author="veasna" date="1252692082"]I don't know how to delete multiple by checkbox in codeigniter. How can i do? for example i used to assign to url like exmple.com/index/delete/2,3,4 but i don't how can i do it?[/quote] When you're creating your check boxes, you will create a checkbox array, like so: Code: <form method="POST"> This, being out put dynamically of course. In your database, you would have a table with an "id" field, which represents 10 and 11 in the above example. When you click both of these buttons, and then click a "delete" button, this will post an associative array that will look like this: Code: array This is quick and dirty...someone else may have a better suggestion, and I - for one - would definitely like to hear it, because I'm always looking for new ways to deal with checkboxes and radio buttons How can we delete multiple by checkbox - El Forum - 09-11-2009 [eluser]NateL[/eluser] @robison.... That's a mess of a code...and the reason why CodeIgniter exists....to avoid procedural jumbled up code like you've posted. Are you attempting to switch all of that over to CodeIgniter? |