Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $server = "localhost";
- $user = "root";
- $pass = "";
- $dbname = "employees";
- $conn = new mysqli($server, $user, $pass, $dbname);
- if($conn->connect_error)
- {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "SELECT emp_no, first_name, last_name FROM employees LIMIT 20";
- $result = $conn->query($sql);
- echo "<!DOCTYPE html>";
- echo "<html>";
- echo "<header>";
- echo "<script>
- function sayValue()
- {
- console.log(document.getElementById('theSelect').value);
- }
- </script>";
- echo "<style>";
- echo "table{
- border-collapse: collapse;
- }";
- echo "table, th, td{
- border: 1px solid black;
- }";
- echo "</style>";
- echo "</header>";
- echo "<body>";
- if($result->num_rows > 0)
- {
- echo "<select onchange=\"sayValue();\" id=\"theSelect\">";
- while($row = $result->fetch_assoc())
- {
- echo "<option value=\"".$row['emp_no']."\">".$row['first_name']."</option>";
- }
- echo "</select>";
- }
- if($result->num_rows > 0)
- {
- echo "<table>";
- while($row = $result->fetch_assoc())
- {
- echo "<tr>";
- echo " <td>";
- echo $row["emp_no"];
- echo " </td>";
- echo " <td>";
- echo $row["first_name"];
- echo " </td>";
- echo " <td>";
- echo $row["last_name"];
- echo " </td>";
- echo "</tr>";
- }
- echo "</table>";
- }
- echo "</body>";
- echo "</html>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement