Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script language=javascript>
- </script>
- </head>
- <body>
- <form method="post" action="part.php">
- <input type="submit" name="submi" value="Datenbank auswerten">
- Sortiere nach Priorität: <input type="checkbox" name="s_priortiy" value="checked">
- Bearbeitungsmodus: <input type="checkbox" name="eMode" value="yes">
- <input type="submit" name="sub" value="Speichern" hidden>
- <?php
- $prioArray=array("Hoch" => "2","Mittel" => "1","Niedrig" => "0");
- function generateSelectPrio($name = '', $options = array(), $default = '') {
- $html = '<select name="'.$name.'">';
- foreach ($options as $option => $value) {
- if ($value == $default) {
- $html .= '<option value='.$value.' selected="selected">'.$option.'</option>';
- } else {
- $html .= '<option value='.$value.'>'.$option.'</option>';
- }
- }
- $html .= '</select>';
- return $html;
- }
- function showPrio($options = array(), $default = ''){
- foreach ($options as $option => $value){
- if ($value == $default) {
- $html = $option;
- }
- }
- return $html;
- }
- error_reporting(E_ALL ^ E_NOTICE);
- $servername = 'localhost';
- $username = 'root';
- $password = '';
- $dbname = 'defect';
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die('Connection failed: ' . $conn->connect_error);
- }
- if ($_POST['s_priortiy'] == 'checked'){
- $sql = 'SELECT id, name, department, object, description, location, room, reg_date, until_date, reason, priority FROM form ORDER BY priority DESC';
- }
- else{
- $sql = 'SELECT id, name, department, object, description, location, room, reg_date, until_date, reason, priority FROM form';
- }
- $result = $conn->query($sql);
- 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>';
- if ($result->num_rows > 0) {
- if($_POST['eMode'] == 'yes'){
- echo '<script language=javascript>
- document.forms[0].submi.value="Speichern";
- </script>
- ';
- while($row = $result->fetch_assoc()) {
- $strPrio = generateSelectPrio("prio", $prioArray, $row['priority']);
- 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>';
- }
- }
- else{
- while($row = $result->fetch_assoc()) {
- $strPrio = showPrio($prioArray, $row['priority']);
- 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>';
- }
- }
- }
- echo '</table></form>';
- $conn->close();
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement