Advertisement
Guest User

Untitled

a guest
Feb 16th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. <?php
  2.  
  3. $servername = "localhost";
  4. $username = "root";
  5. $password = "root";
  6. $database = "lamp2proj1";
  7.  
  8. // Create connection
  9. $connection = new mysqli($servername, $username, $password, $database);
  10.  
  11. if ($connection->connect_error)
  12. {
  13. die("Connection failed: " . $connection->connect_error);
  14. }
  15.  
  16. $tasks = $connection->query('SELECT * FROM task ');
  17. ?>
  18. <table style='border:1px solid black;' border='1'>
  19. <tr>
  20. <th></th>
  21. <th>Description</th>
  22. <th>Priority</th>
  23. <th>Date Created</th>
  24. <th>Date Completed</th>
  25. </tr>
  26. <?php if($tasks)
  27. {
  28. while ($row = $tasks->fetch_array())
  29. {
  30. echo
  31. "<tr>
  32. <td><input class='taskrow' checked type='checkbox'/ value=".$row['id']."></td>
  33. <td>".$row['description']."</td>
  34. <td>".$row['priority']."</td>
  35. <td>".$row['dateCreated']."</td>
  36. <td>".$row['dateCompleted']."</td>
  37. <td>
  38. <a data-id=".$row['id']." href=\"#\">Delete</a>
  39. </td>
  40. </tr>";
  41. }
  42. }
  43. ?>
  44. </table>
  45. <button id="deleteRows">Delete</button>
  46.  
  47. <script src="jquery.min.js"></script>
  48. <script>
  49.  
  50. $('[data-id]').each(function() {
  51. $(this).on('click', function(event) {
  52. event.preventDefault();
  53. deleteRow([$(this).data('id')]);
  54. });
  55. });
  56.  
  57. $('#deleteRows').on('click', function(event) {
  58. var obj = [];
  59. $('.taskrow:checked').each(function() {
  60. obj.push(parseInt($(this).val(), 10));
  61. });
  62. deleteRow(obj);
  63. });
  64.  
  65. function deleteRow(ids) {
  66. $.ajax({ url: 'Proj1Structure.php',
  67. data: {
  68. action: 'delete',
  69. data: JSON.stringify(ids)
  70. },
  71. type: 'post',
  72. success: function(output) {
  73. console.log(output);
  74. location.reload();
  75. }
  76. });
  77. }
  78.  
  79. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement