Advertisement
Guest User

Untitled

a guest
Oct 26th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. <?php
  2.     $server = "localhost";
  3.     $user = "root";
  4.     $pass = "";
  5.     $dbname = "employees";
  6.    
  7.     $conn = new mysqli($server, $user, $pass, $dbname);
  8.     if($conn->connect_error)
  9.     {
  10.         die("Connection failed: " . $conn->connect_error);
  11.     }
  12.    
  13.     $sql = "SELECT emp_no, first_name, last_name FROM employees LIMIT 20";
  14.     $result = $conn->query($sql);
  15.     echo "<!DOCTYPE html>";
  16.     echo "<html>";
  17.     echo "<header>";
  18.    
  19.     echo "<script>
  20.         function sayValue()
  21.         {
  22.             console.log(document.getElementById('theSelect').value);
  23.         }
  24.     </script>";
  25.    
  26.     echo "<style>";
  27.     echo "table{
  28.         border-collapse: collapse;
  29.     }";
  30.     echo "table, th, td{
  31.         border: 1px solid black;
  32.     }";
  33.     echo "</style>";
  34.     echo "</header>";
  35.     echo "<body>";
  36.    
  37.     if($result->num_rows > 0)
  38.     {
  39.         echo "<select onchange=\"sayValue();\" id=\"theSelect\">";
  40.         while($row = $result->fetch_assoc())
  41.         {
  42.             echo "<option value=\"".$row['emp_no']."\">".$row['first_name']."</option>";
  43.         }
  44.         echo "</select>";
  45.     }  
  46.    
  47.     if($result->num_rows > 0)
  48.     {
  49.         echo "<table>";
  50.         while($row = $result->fetch_assoc())
  51.         {
  52.             echo "<tr>";
  53.             echo "  <td>";
  54.             echo $row["emp_no"];
  55.             echo "  </td>";
  56.             echo "  <td>";
  57.             echo $row["first_name"];
  58.             echo "  </td>";
  59.             echo "  <td>";
  60.             echo $row["last_name"];
  61.             echo "  </td>";
  62.             echo "</tr>";
  63.         }
  64.         echo "</table>";
  65.     }
  66.     echo "</body>";
  67.     echo "</html>";
  68. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement