Advertisement
GWibisono

budayakan pastebin

Aug 9th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.83 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Menghapus Multiple Data Via AJAX Dengan jQuery</title>
  6. <style>
  7. body{
  8. font-family:Arial;
  9. font-size:12px;
  10. }
  11. a:hover{
  12. padding:3px;
  13. background:‪#‎FF9900‬;
  14. text-decoration:none;
  15. color:#000000;
  16. }
  17. a{
  18. padding:3px;
  19. text-decoration:none;
  20. color:#000000;
  21. }
  22. </style>
  23. <script type="text/javascript" src="jquery.js"></script>
  24. <script type="text/javascript">
  25. $(document).ready(function(){
  26. var url = "data-data.php";
  27. $("‪#‎showdata‬").load(url);
  28. $("‪#‎selectall‬").live("click", function()
  29. {
  30. $('.chk').attr('checked', this.checked);
  31. });
  32. // if all checkbox are selected, check the selectall checkbox
  33. // and viceversa
  34. $(".chk").live("click", function()
  35. {
  36. if($(".chk").length == $(".chk:checked").length)
  37. {
  38. $("#selectall").attr("checked", "checked");
  39. }
  40. else
  41. {
  42. $("#selectall").removeAttr("checked");
  43. }
  44. });
  45. $("a.hapus").live("click", function() {
  46. var url = "delete.php";
  47. var id_array = new Array();
  48. i=0;
  49. $("input.chk:checked").each(function(){
  50. id_array[i] = $(this).val();
  51. i++;
  52. });
  53. $.post(url, {kode: id_array}, function(respon)
  54. {
  55. if(respon==1)
  56. {
  57. $("input.chk:checked").each(function()
  58. {
  59. $(this).parent().parent().remove('.chk').animate({ opacity: "hide" }, "slow");
  60. });
  61. }
  62. });
  63. });
  64. });
  65. </script>
  66. </head>
  67. <body>
  68. <div id="showdata"></div>
  69. </body>
  70. </html>
  71. script untuk data-data.php:
  72. <?php
  73. include('koneksi.php');
  74. $qu = mysql_query("select * from tbl_orang");
  75. if(mysql_num_rows($qu)<1)
  76. {
  77. mysql_query("INSERT INTO tbl_orang (`id_orang`, `nama`) VALUES (NULL, 'Gede Lumbung'), (NULL, 'Budi Raharjo'), (NULL, 'Ivan Gunawan'), (NULL, 'Thomas Lorenzo'), (NULL, 'Roy Suryo'), (NULL, 'Surya Husada'), (NULL, 'Pratama Antara'), (NULL, 'Widya Sari'), (NULL, 'Asti Sri Astuti'), (NULL, 'Omla Ramlan'), (NULL, 'Budi Raharjo'), (NULL, 'Engkong Satu'), (NULL, 'Engkong Dua'), (NULL, 'Engkong Tiga'), (NULL, 'Engkong Muda')");
  78. }
  79. ?>
  80. <table cellpadding="5" cellspacing="0" border="1">
  81. <tr align="center"><td><a href="#" class="hapus">Hapus</a></td><td>Kode Dosen</td><td>Nama Dosen</td></tr>
  82. <?php
  83. $q = mysql_query("select * from tbl_orang");
  84. $no=1;
  85. while($b = mysql_fetch_array($q))
  86. {
  87. ?>
  88. <tr align="center">
  89. <td><input type="checkbox" value="<?php echo $b["id_orang"]; ?>" class="chk"/></td>
  90. <td><?php echo $b["id_orang"]; ?></td>
  91. <td><?php echo $b["nama"]; ?></td>
  92. </tr>
  93. <?php
  94. $no++;
  95. }
  96. ?>
  97. <tr><td colspan="3"><input type="checkbox" name="pilih" id="selectall"</td></tr>
  98. </table>
  99. script untuk delete.php:
  100. <?php
  101. include('koneksi.php');
  102. $kode_orang=$_POST['kode'];
  103. $query = mysql_query('delete from tbl_orang where id_orang in ('.$kode_orang.')');
  104. echo 1;
  105. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement