Advertisement
Guest User

Untitled

a guest
Jan 15th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. <html>
  2. <head>
  3. <script language=javascript>
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10. </script>
  11. </head>
  12. <body>
  13. <form method="post" action="part.php">
  14.  
  15.  
  16.  
  17. <input type="submit" name="submi" value="Datenbank auswerten">
  18.  
  19. Sortiere nach Priorität: <input type="checkbox" name="s_priortiy" value="checked">
  20.  
  21. Bearbeitungsmodus: <input type="checkbox" name="eMode" value="yes">
  22.  
  23. <input type="submit" name="sub" value="Speichern" hidden>
  24.  
  25.  
  26.  
  27.  
  28.  
  29. <?php
  30.  
  31. $prioArray=array("Hoch" => "2","Mittel" => "1","Niedrig" => "0");
  32.  
  33. function generateSelectPrio($name = '', $options = array(), $default = '') {
  34. $html = '<select name="'.$name.'">';
  35. foreach ($options as $option => $value) {
  36. if ($value == $default) {
  37. $html .= '<option value='.$value.' selected="selected">'.$option.'</option>';
  38. } else {
  39. $html .= '<option value='.$value.'>'.$option.'</option>';
  40. }
  41. }
  42.  
  43. $html .= '</select>';
  44. return $html;
  45. }
  46. function showPrio($options = array(), $default = ''){
  47.  
  48. foreach ($options as $option => $value){
  49.  
  50. if ($value == $default) {
  51. $html = $option;
  52. }
  53. }
  54.  
  55. return $html;
  56. }
  57.  
  58.  
  59.  
  60. error_reporting(E_ALL ^ E_NOTICE);
  61. $servername = 'localhost';
  62. $username = 'root';
  63. $password = '';
  64. $dbname = 'defect';
  65.  
  66. // Create connection
  67. $conn = new mysqli($servername, $username, $password, $dbname);
  68. // Check connection
  69. if ($conn->connect_error) {
  70. die('Connection failed: ' . $conn->connect_error);
  71. }
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83. if ($_POST['s_priortiy'] == 'checked'){
  84.  
  85.  
  86.  
  87. $sql = 'SELECT id, name, department, object, description, location, room, reg_date, until_date, reason, priority FROM form ORDER BY priority DESC';
  88. }
  89. else{
  90. $sql = 'SELECT id, name, department, object, description, location, room, reg_date, until_date, reason, priority FROM form';
  91. }
  92. $result = $conn->query($sql);
  93.  
  94. echo '<table border="1"><tr><th>ID</th><th>Name</th><th>Abteilung</th><th>Thema</th><th>Beschreibung</th><th>Ort</th><th>Aufgegeben um</th><th>Bis Datum</th><th>weil</th><th>Prirorität</th>';
  95.  
  96. if ($result->num_rows > 0) {
  97.  
  98. if($_POST['eMode'] == 'yes'){
  99.  
  100.  
  101.  
  102. echo '<script language=javascript>
  103.  
  104. document.forms[0].submi.value="Speichern";
  105.  
  106. </script>
  107. ';
  108.  
  109. while($row = $result->fetch_assoc()) {
  110. $strPrio = generateSelectPrio("prio", $prioArray, $row['priority']);
  111.  
  112.  
  113. echo '<tr><td>' . $row['id']. '</td><td>'.$row['name'].' </td><td> ' . $row['department']. ' </td><td> ' . $row['object']. ' </td><td> ' . $row['description']. ' </td><td> ' . $row['location'].' '. $row['room']. ' </td><td> ' . $row['reg_date']. ' </td><td> ' . $row['until_date']. ' </td><td> ' . $row['reason'].'</td><td>'.$strPrio.'</td></tr>';
  114. }
  115.  
  116. }
  117. else{
  118.  
  119. while($row = $result->fetch_assoc()) {
  120.  
  121. $strPrio = showPrio($prioArray, $row['priority']);
  122.  
  123. echo '<tr><td>' . $row['id']. '</td><td>' . $row['name']. ' </td><td> ' . $row['department']. ' </td><td> ' . $row['object']. ' </td><td> ' . $row['description']. ' </td><td> ' . $row['location'].' '. $row['room']. ' </td><td> ' . $row['reg_date']. ' </td><td> ' . $row['until_date']. ' </td><td> ' . $row['reason'].'</td><td>'. $strPrio.'</td></tr>';
  124. }
  125. }
  126. }
  127. echo '</table></form>';
  128.  
  129.  
  130.  
  131. $conn->close();
  132. ?>
  133. </body>
  134. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement